package com.ruoyi.web.controller.platform;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.db.DSqlKit;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.HealthPatInfoService;
import com.ruoyi.web.util.HttpUrlConnectionToInterface;
import com.ruoyi.web.util.ReadTpltoStr;
import com.ruoyi.web.util.Xml2Json;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.*;

@Controller
@RequestMapping("/healthpatinfo")
public class HealthPatInfoController
{
    private final Logger logger = LoggerFactory.getLogger(getClass());

   private static final String _INFURL ="https://59.211.16.98:19438/BasWebService.asmx?wsdl"; //正试环境地址

    @Autowired
    private HealthPatInfoService healthPatInfoService;

//        2DF4X 马源
//        2D5UQ  吕胤
    /**
     * 要先上传宫颈癌病史情况，才能上传 宫颈癌 HPV 检查 信息
     * @param sendOrderId
     * @param tableName
     * @return
     */
    @RequestMapping("/uploadinfo")
    @ResponseBody
    public String uploadinfo(@RequestParam(value = "sendOrderId", required = true) String sendOrderId,
                             @RequestParam(value = "tableName", required = true) String tableName
    )
    {
        String resultMsg ="1";
        if("GJGBS".equals(tableName))
        {
            //保存宫颈癌病史情况
            resultMsg = this.SaveGjgBsqk(sendOrderId,tableName);
        }
        else if("GJGHPVJC".equals(tableName))
        {
            //宫颈癌 HPV 检查
            resultMsg = this.saveGjgHpv(sendOrderId,tableName);
        }
        else if("GJGXBXJC".equals(tableName))
        {
            //宫颈癌细胞学检查孕前优生基本信息上传
            resultMsg = this.saveGjgXbxjcMk(sendOrderId,tableName);
        }
        else if("GJGYDJJC".equals(tableName))
        {
            //宫颈癌阴道镜检查
            resultMsg = this.saveGjgYdjjc(sendOrderId,tableName);
        }
        else if("GJGZZXJC".equals(tableName))
        {
            //宫颈癌病理学检查 SaveGjgZzxjc
            resultMsg = this.saveGjgZzxjc(sendOrderId,tableName);
        }
        else if("GJGZHZD".equals(tableName))
        {
            //宫颈癌最后诊断
            resultMsg = this.saveGjgZhzd(sendOrderId,tableName);
        }
        else if("GJGSF".equals(tableName))
        {
            //宫颈癌最后随访
            resultMsg = this.saveGjgZhsf(sendOrderId,tableName);
        }
        else if("RXABS".equals(tableName))
        {
            //乳腺癌病史信息
            resultMsg = this.saveRxgBsxx(sendOrderId,tableName);
        }
        else if("RXAXX".equals(tableName))
        {
            //乳腺癌 x 线检查
            resultMsg = this.saveRxxxxx(sendOrderId,tableName);
        }
        else if("RXASF".equals(tableName))
        {
            //乳腺癌最终随访
            resultMsg = this.saveZzsfxx(sendOrderId,tableName);
        }
        else
        {
            logger.info("**上传接口建设中**");
        }

        return resultMsg;
    }

    @RequestMapping("/saveGjgHpv")
    @ResponseBody
    public String saveGjgHpv(@RequestParam(value = "sendOrderId", required = true) String sendOrderId,
                             @RequestParam(value = "tableName", required = true) String tableName
                             )
    {
        logger.info("******宫颈癌 HPV 检查******开始调用【SaveGjgHpv接口】");
        logger.info("****入参 批次:"+sendOrderId +",表名："+tableName);

        String resultMsg ="1";
        HashMap qryparam  = new HashMap();
        qryparam.put("sendOrderId",sendOrderId);
        qryparam.put("tableName",tableName);
        List<HashMap> uploadList = healthPatInfoService.queryUploadGjgHPV(qryparam);
       // List<HashMap> errList = new ArrayList<HashMap>();
        for (HashMap info:uploadList)
        {
            try {
                if (info != null) {
                  //  先用主索引接口 获取主索引 再上传病史生成 档案  再查询档案 上传对应检查后，QeuryGJAIDByIdNo 才会有记录
                    //查询 QeuryGJAIDByIdNo 接口，获取 pId与 personIndex
                    String peId = String.valueOf(info.get("PE_ID") == null ? "" : info.get("PE_ID"));
                    String visitid = String.valueOf(info.get("PE_VISIT_ID") == null ? "0" : info.get("PE_VISIT_ID"));
                    String idNo = String.valueOf(info.get("ID_NO") == null ? "" : info.get("ID_NO"));
                    logger.info("****身份证号："+idNo);
                    if ("".equals(idNo)) {
                        logger.info("****身份证号为空不能上传");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","身份证号为空不能上传");
                        updateUploadStatus(updateparam);
                        continue;
                    }

                    HashMap params1 = new HashMap();
                    params1.put("IdNo",idNo);
                    String tpl1 = ReadTpltoStr.readTol("tpl_QeuryGJAIDByIdNo.xml");
                    String tpl1ReqXml = fillParamsToTpl(tpl1,params1 );
                    logger.info("****入参:"+ tpl1ReqXml );
                    String result1 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl1ReqXml,_INFURL);
                    logger.info("****出参:"+result1);

                    if(result1==null ||"".equals(result1))
                    {
                        //errList.add(info);
                        logger.info("****接口：QeuryGJAIDByIdNo查询失败，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo查询失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json1 =  Xml2Json.xmltoJson(result1);
                    //{"Envelope":{"Body":{"QeuryGJAIDByIdNoResponse":{"QeuryGJAIDByIdNoResult":"{\"SUCCESS\":\"1\",\"MESSAGE\":\"\",\"DATA\":[]}"}}}}
                    JSONObject envelopeObj = (JSONObject) json1.get("Envelope");
                    JSONObject bodyObj = (JSONObject) envelopeObj.get("Body");
                    JSONObject qeuryGJAIDByIdNoResponseObj = (JSONObject) bodyObj.get("QeuryGJAIDByIdNoResponse");
                    JSONObject qeuryGJAIDByIdNoResultObj =JSONObject.parseObject (String.valueOf( qeuryGJAIDByIdNoResponseObj.get("QeuryGJAIDByIdNoResult")));

                    String resultCode1 = qeuryGJAIDByIdNoResultObj.getString("SUCCESS");
                    String msg1 = qeuryGJAIDByIdNoResultObj.getString("MESSAGE");
                    if(!"1".equals(resultCode1))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo查询失败，"+msg1);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg1.length()>50){
                            updateparam.put("errMsg","接口：SaveGjgHpv上传失败"+msg1.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：SaveGjgHpv上传失败"+msg1);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONArray data1arr = qeuryGJAIDByIdNoResultObj.getJSONArray("DATA");
                    if(data1arr==null || (data1arr!=null && data1arr.size()==0))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 返回结果中DATA为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
//{"SUCCESS":"1","MESSAGE":"","DATA":[{"PE_ID":"6407a78c-0c09-4fa9-926f-5aa2f04fa946","PERSON_INDEX":"073826501","ID_NO":"452128198307116045","YEAR_REPORTED":"2022","QUARTERLY_REPORTED":"3","BH":""}]}
//                    JSONObject data1Index0 = (JSONObject) data1arr.get(0);
//                    String pId = String.valueOf(data1Index0.get("PE_ID") == null ? "" : data1Index0.get("PE_ID"));
//                    String personIndex = String.valueOf(data1Index0.get("PERSON_INDEX") == null ? "" : data1Index0.get("PERSON_INDEX"));
                    String pId="";
                    String personIndex="";
                    //返回的数据有多条，要找到对应体检号这条
                    for (int i = 0; i < data1arr.size(); i++) {
                        JSONObject jsonObject = data1arr.getJSONObject(i);
                        String PE_ID = jsonObject.getString("PE_ID");
                        if (PE_ID.equals(peId+visitid)) {
                            pId = String.valueOf(jsonObject.get("PE_ID") == null ? "" : jsonObject.get("PE_ID"));
                            personIndex = String.valueOf(jsonObject.get("PERSON_INDEX") == null ? "" : jsonObject.get("PERSON_INDEX"));
                        }
                    }
                    logger.info("****接口：QeuryGJAIDByIdNo 返回结果中PId："+pId +",personIndex:"+personIndex);
                    if("".equals(pId))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA中：PE_ID为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 返回结果中DATA中：PE_ID为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    if("".equals(personIndex))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA中：person_index为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 返回结果中DATA中：person_index为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    //上报 SaveGjgHpv
                    HashMap params2 = new HashMap();

                    params2.put("peId",peId);
                    params2.put("visitid",visitid);

                    //上传的体检号=体检号+体检次数
                    String getPeId = peId + visitid;
                    params2.put("getPeId",getPeId);

                    params2.put("personIndex",personIndex);
                    params2.put("pId",pId);

                    //测试数据
                   // params2.put("personIndex","9999");
                   // params2.put("pId","TJ01937443");

                    String hpvCheck = String.valueOf(info.get("HPV_CHECK") == null ? "" : info.get("HPV_CHECK"));
                    params2.put("hpvCheck",hpvCheck);

                    String sixteen = String.valueOf(info.get("SIXTEEN") == null ? "" : info.get("SIXTEEN"));
                    params2.put("sixteen",sixteen);

                    String eighteen = String.valueOf(info.get("EIGHTEEN") == null ? "" : info.get("EIGHTEEN"));
                    params2.put("eighteen",eighteen);

                    String thirtyOne = String.valueOf(info.get("THIRTY_ONE") == null ? "" : info.get("THIRTY_ONE"));
                    params2.put("thirtyOne",thirtyOne);

                    String thirtyThree = String.valueOf(info.get("THIRTY_THREE") == null ? "" : info.get("THIRTY_THREE"));
                    params2.put("thirtyThree",thirtyThree);

                    String thirtyFive = String.valueOf(info.get("THIRTY_FIVE") == null ? "" : info.get("THIRTY_FIVE"));
                    params2.put("thirtyFive",thirtyFive);

                    String fortyFive = String.valueOf(info.get("FORTY_FIVE") == null ? "" : info.get("FORTY_FIVE"));
                    params2.put("fortyFive",fortyFive);

                    String fiftyTwo = String.valueOf(info.get("FIFTY_TWO") == null ? "" : info.get("FIFTY_TWO"));
                    params2.put("fiftyTwo",fiftyTwo);

                    String fiftyEight = String.valueOf(info.get("FIFTY_EIGHT") == null ? "" : info.get("FIFTY_EIGHT"));
                    params2.put("fiftyEight",fiftyEight);

                    String furtherExamination = String.valueOf(info.get("FURTHER_EXAMINATION") == null ? "" : info.get("FURTHER_EXAMINATION"));
                    params2.put("furtherExamination",furtherExamination);

                    String cervicalCytology = String.valueOf(info.get("CERVICAL_CYTOLOGY") == null ? "" : info.get("CERVICAL_CYTOLOGY"));
                    params2.put("cervicalCytology",cervicalCytology);

                    String via = String.valueOf(info.get("VIA") == null ? "" : info.get("VIA"));
                    params2.put("via",via);

                    String colposcopy = String.valueOf(info.get("COLPOSCOPY") == null ? "" : info.get("COLPOSCOPY"));
                    params2.put("colposcopy",colposcopy);

                    String checkPerson = String.valueOf(info.get("DOCTOR_NAME") == null ? "" : info.get("DOCTOR_NAME"));
                    params2.put("checkPerson",checkPerson);

                    String checkDatestr = String.valueOf(info.get("PE_DATE") == null ? "" : info.get("PE_DATE"));
                    String checkDate ="";
                    if(!("".equals(checkDatestr)))
                    {
                        checkDate = checkDatestr.substring(0,10);
                    }
                    params2.put("checkDate",checkDate);


                    String hpvTyping = String.valueOf(info.get("HPV_TYPING") == null ? "" : info.get("HPV_TYPING"));
                    params2.put("hpvTyping",hpvTyping);

                    String other = String.valueOf(info.get("OTHER") == null ? "" : info.get("OTHER"));
                    params2.put("other",other);


                    //
                    String tpl2 = ReadTpltoStr.readTol("tpl_SaveGjgHpv.xml");
                    String tpl2ReqXml = fillParamsToTpl(tpl2,params2 );
                    logger.info("****入参:"+ tpl2ReqXml );
                    String result2 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl2ReqXml,_INFURL);
                    logger.info("****出参:"+result2);

                    if(result2==null ||"".equals(result2))
                    {
                       // errList.add(info);
                        logger.info("****接口：SaveGjgHpv上传失败，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：SaveGjgHpv上传失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json2 =  Xml2Json.xmltoJson(result2);
                    logger.info("****json2"+json2);
                    //{"Envelope":{"Body":{"SaveGjgHpvResponse":{"SaveGjgHpvResult":"{\"SUCCESS\":\"0\",\"MESSAGE\":\"0,父节点不能为空\",\"DATA\":[]}"}}}}
                    JSONObject envelopeObj2 = (JSONObject) json2.get("Envelope");
                    JSONObject bodyObj2 = (JSONObject) envelopeObj2.get("Body");
                    JSONObject saveGjgHpvResponseObj2 = (JSONObject) bodyObj2.get("SaveGjgHpvResponse");
                    JSONObject saveGjgHpvResult2 =JSONObject.parseObject (String.valueOf( saveGjgHpvResponseObj2.get("SaveGjgHpvResult")));

                    String resultCode2 = saveGjgHpvResult2.getString("SUCCESS");
                    String msg2 = saveGjgHpvResult2.getString("MESSAGE");
                    if(!"1".equals(resultCode2))
                    {
                        logger.info("****接口：SaveGjgHpv上传失败，"+msg2);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg2.length()>50){
                            updateparam.put("errMsg","接口：SaveGjgHpv上传失败"+msg2.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：SaveGjgHpv上传失败"+msg2);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }

                    //更新 上传状态
                    HashMap updateparam  = new HashMap();
                    updateparam.put("peId",peId);
                    updateparam.put("visitid",visitid);
                    updateparam.put("idNo",idNo);
                    updateparam.put("sendOrderId",sendOrderId);
                    updateparam.put("tableName",tableName);
                    updateparam.put("uploadStatus","1");
                    updateparam.put("errMsg","succ");
                    updateUploadStatus(updateparam);

                }
            }catch (Exception e){
                //errList.add(info);
                e.printStackTrace();
            }
        }
        return resultMsg;
    }


    public void updateUploadStatus(HashMap updateparam)
    {
        try {
            healthPatInfoService.updateGjgHPV(updateparam);
        }catch (Exception  e){
            e.printStackTrace();
        }
    }


    public String fillParamsToTpl(String orgTplStr, HashMap params )
    {
        logger.info("****原始模板："+orgTplStr);

        LoginUser loginUser = SecurityUtils.getLoginUser();
//        System.out.println(loginUser);
//        System.out.println(loginUser.getUser().getEmail());
        if(!ObjectUtils.isEmpty(loginUser.getUser().getEmail()))
        {
            params.put("userCode",loginUser.getUser().getEmail());
        }
        else{
            logger.info("****上传人员代码不能为空：");
            return "上传人员代码不能为空";
        }

//        System.out.println(params);
        String retTplStr = orgTplStr;
        for (Iterator<? extends Map.Entry<String, ? extends Object>> it = params.entrySet().iterator(); it.hasNext();)
        {
            Map.Entry<String, ? extends Object> entry = it.next();
            String keyStr = entry.getKey();
            String txtval = String.valueOf(entry.getValue()==null?"":entry.getValue());
            retTplStr = retTplStr.replaceAll("\\#\\{"+keyStr+"\\}",txtval);
        }
        logger.info("****请求模板："+retTplStr);
        return retTplStr;
    }


    @RequestMapping("/populationIndex")
    @ResponseBody
    public String populationIndex(@RequestParam(value = "idNo", required = true) String idNo
    ) {
        logger.info("******全区人口主索引******开始调用【populationIndex接口】");
        logger.info("****入参 身份证号:" + idNo );
        HashMap params1 = new HashMap();
        params1.put("IdNo",idNo);
        String tpl1 = ReadTpltoStr.readTol("tpl_PopulationIndex.xml");
        String tpl1ReqXml = fillParamsToTpl(tpl1,params1 );
        logger.info("****入参:"+ tpl1ReqXml );
        String result1 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl1ReqXml,_INFURL);
        logger.info("****出参:"+result1);
        return result1;
    }

    @RequestMapping("/saveGjgBsqk")
    @ResponseBody
    public String SaveGjgBsqk(@RequestParam(value = "sendOrderId", required = true) String sendOrderId,
                              @RequestParam(value = "tableName", required = true) String tableName
    ) {
        logger.info("******保存宫颈癌病史情况******开始调用【SaveGjgBsqk接口】");
        logger.info("****入参 批次:"+sendOrderId +",表名："+tableName);

        String resultMsg ="1";
        HashMap qryparam  = new HashMap();
        qryparam.put("sendOrderId",sendOrderId);
        qryparam.put("tableName",tableName);
        List<HashMap> uploadList = healthPatInfoService.queryUploadGjgBsqk(qryparam);
        for (HashMap info:uploadList)
        {
            try {
                if (info != null) {
                    String peId = String.valueOf(info.get("PE_ID") == null ? "" : info.get("PE_ID"));
                    String visitid = String.valueOf(info.get("PE_VISIT_ID") == null ? "0" : info.get("PE_VISIT_ID"));
                    String idNo = String.valueOf(info.get("ID_NO") == null ? "" : info.get("ID_NO"));
                    logger.info("****身份证号：" + idNo);
                    if ("".equals(idNo)) {
                        logger.info("****身份证号为空不能上传");
                        //更新 上传状态
                        HashMap updateparam = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo", idNo);
                        updateparam.put("sendOrderId", sendOrderId);
                        updateparam.put("tableName", tableName);
                        updateparam.put("uploadStatus", "0");
                        updateparam.put("errMsg", "身份证号为空不能上传");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    String result1 = this.populationIndex(idNo);
                    if(result1==null ||"".equals(result1))
                    {
                        //errList.add(info);
                        logger.info("****接口：populationIndex查询失败，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：populationIndex查询失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json1 =  Xml2Json.xmltoJson(result1);
                    JSONObject envelopeObj = (JSONObject) json1.get("Envelope");
                    JSONObject bodyObj = (JSONObject) envelopeObj.get("Body");
                    JSONObject populationIndexResponseObj = (JSONObject) bodyObj.get("PopulationIndexResponse");
                    String xmlResult1 = String.valueOf( populationIndexResponseObj.get("PopulationIndexResult"));
                    if(xmlResult1==null || "".equals(xmlResult1))
                    {
                        logger.info("****接口：populationIndex查询失败，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：populationIndex查询失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    else
                    {
                        if("0".equals(xmlResult1))
                        {
                            logger.info("****接口：populationIndex查询失败，返回为空！");
                            //更新 上传状态
                            HashMap updateparam  = new HashMap();
                            updateparam.put("peId",peId);
                            updateparam.put("visitid",visitid);
                            updateparam.put("idNo",idNo);
                            updateparam.put("sendOrderId",sendOrderId);
                            updateparam.put("tableName",tableName);
                            updateparam.put("uploadStatus","0");
                            updateparam.put("errMsg","接口：populationIndex查询失败，返回为空");
                            updateUploadStatus(updateparam);
                            continue;
                        }
                        JSONObject jsonXmlResult1 =  Xml2Json.xmltoJson(xmlResult1);
                        //{"response":{"index":{"person":{"dead_tag":"0","charge_type":"","nation":"壮族","date_of_birth":"1983/7/11","out_poverty_status":"","lastunit":"广西壮族自治区人民医院","next_of_kin":"","tprq":"","zip_code":"","next_of_kin_zip_code":"","phone_number_home":"13471195860","id_no":"452128198307116045","attached_address":"建政东路39号2栋401","identity":"","mailing_address4":"广西壮族自治区南宁市青秀区新竹街道办事处建政社区居委会","unit_in_contract":"11","relationship":"","mailing_address1":"广西壮族自治区南宁市青秀区","mailing_address2":"广西壮族自治区南宁市青秀区津头街道办事处滨湖社区居委会","mailing_address3":"广西壮族自治区南宁市青秀区","birth_place2":"广西壮族自治区南宁市青秀区津头街道办事处滨湖社区居委会","sex":"女","birth_place1":"广西壮族自治区南宁市青秀区","citizenship":"中国","next_of_kin_addr":"","next_of_kin_phone":"","attached_hujiaddress":"","phone_number_business":"","marital_status":"初婚","lasttime":"2016/8/17","lastuser":"张桂红","patient_id":"073826501","name":"农建萍","health_card_id":"","ispoor":"0","health_record_code":""}}}}
                        JSONObject responseObj = (JSONObject) jsonXmlResult1.get("response");
                        JSONObject indexObj = (JSONObject) responseObj.get("index");
//                        JSONObject personObj = (JSONObject) indexObj.get("person");
                        JSONObject personObj = new JSONObject();
                        //返回可能有两条数据
                        if (indexObj.getString("person").startsWith("["))
                        {
                            //属性值是json数组
                            JSONArray personObjarry = (JSONArray) indexObj.get("person");
                            personObj = (JSONObject) personObjarry.get(0);
                        }
                        else if (indexObj.getString("person").startsWith("{")) {
                            //属性值是json对象
                            personObj = (JSONObject) indexObj.get("person");
                        }

                        if(personObj.isEmpty())
                        {
                            logger.info("****接口：populationIndex查询失败，返回为空！");
                            //更新 上传状态
                            HashMap updateparam  = new HashMap();
                            updateparam.put("peId",peId);
                            updateparam.put("visitid",visitid);
                            updateparam.put("idNo",idNo);
                            updateparam.put("sendOrderId",sendOrderId);
                            updateparam.put("tableName",tableName);
                            updateparam.put("uploadStatus","0");
                            updateparam.put("errMsg","查询接口：populationIndex,返回patient_id为空");
                            updateUploadStatus(updateparam);
                            continue;
                        }
                        String patient_id = (String) personObj.get("patient_id"); //主索引ID
                        if(patient_id==null || "".equals(patient_id))
                        {
                            logger.info("****接口：populationIndex查询失败，返回为空！");
                            //更新 上传状态
                            HashMap updateparam  = new HashMap();
                            updateparam.put("peId",peId);
                            updateparam.put("visitid",visitid);
                            updateparam.put("idNo",idNo);
                            updateparam.put("sendOrderId",sendOrderId);
                            updateparam.put("tableName",tableName);
                            updateparam.put("uploadStatus","0");
                            updateparam.put("errMsg","查询接口：populationIndex,返回patient_id为空");
                            updateUploadStatus(updateparam);
                            continue;
                        }

                        //保存宫颈癌病史情况 SaveGjgBsqk
                        HashMap params2 = new HashMap();

                        params2.put("peId",peId);
                        params2.put("visitid",visitid);

                        //上传的体检号=体检号+体检次数
                        String getPeId = peId + visitid;
                        params2.put("getPeId",getPeId);

                        params2.put("personIndex",patient_id);

                        String education = String.valueOf(info.get("EDUCATION") == null ? "" : info.get("EDUCATION"));
                        params2.put("education",education);

                        String dxlx = String.valueOf(info.get("DXLX") == null ? "" : info.get("DXLX"));
                        params2.put("dxlx",dxlx);

                        String czknfn = String.valueOf(info.get("CZKNFN") == null ? "" : info.get("CZKNFN"));
                        params2.put("czknfn",czknfn);


                        Calendar calendar = Calendar.getInstance();
                        int year = calendar.get(Calendar.YEAR);
                        int curmonth = calendar.get(Calendar.MONTH)+1;
                        int quarterly =1;
                        if(curmonth>=1 && curmonth <=3)
                        {
                            quarterly =1;
                        }
                        else if(curmonth>=4 && curmonth <=6)
                        {
                            quarterly =2;
                        }
                        else if(curmonth>=7 && curmonth <=9)
                        {
                            quarterly =3;
                        }
                        else if(curmonth>=10 && curmonth <=12)
                        {
                            quarterly =4;
                        }
                        else{}

                        String yearReported = String.valueOf(info.get("YEAR_REPORTED") == null ? ""+year : info.get("YEAR_REPORTED"));
                        params2.put("yearReported",yearReported);

                        String quarterlyReported = String.valueOf(info.get("QUARTERLY_REPORTED") == null ? ""+quarterly : info.get("QUARTERLY_REPORTED"));
                        params2.put("quarterlyReported",quarterlyReported);

                        String lastMenstrualPeriodStr = String.valueOf(info.get("LAST_MENSTRUAL_PERIOD") == null ? "" : info.get("LAST_MENSTRUAL_PERIOD"));
                        String lastMenstrualPeriod ="";
                        if(!("".equals(lastMenstrualPeriodStr)))
                        {
                            lastMenstrualPeriod = lastMenstrualPeriodStr.substring(0,10);
                        }
                        params2.put("lastMenstrualPeriod",lastMenstrualPeriod);

                        String treated = String.valueOf(info.get("TREATED") == null ? "" : info.get("TREATED"));
                        params2.put("treated",treated);

                        String treatedYear = String.valueOf(info.get("TREATED_YEAR") == null ? "" : info.get("TREATED_YEAR"));
                        params2.put("treatedYear",treatedYear);

                        String bh = String.valueOf(info.get("BH") == null ? "" : info.get("BH"));
                        params2.put("bh",bh);


                        String tpl2 = ReadTpltoStr.readTol("tpl_SaveGjgBsqk.xml");
                        String tpl2ReqXml = fillParamsToTpl(tpl2,params2 );
                        logger.info("****入参:"+ tpl2ReqXml );
                        String result2 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl2ReqXml,_INFURL);
                        logger.info("****出参:"+result2);

                        if(result2==null ||"".equals(result2))
                        {
                            // errList.add(info);
                            logger.info("****接口：SaveGjgBsqk上传失败，返回为空！");
                            //更新 上传状态
                            HashMap updateparam  = new HashMap();
                            updateparam.put("peId",peId);
                            updateparam.put("visitid",visitid);
                            updateparam.put("idNo",idNo);
                            updateparam.put("sendOrderId",sendOrderId);
                            updateparam.put("tableName",tableName);
                            updateparam.put("uploadStatus","0");
                            updateparam.put("errMsg","接口：SaveGjgBsqk上传失败，返回为空");
                            updateUploadStatus(updateparam);
                            continue;
                        }
                        JSONObject json2 =  Xml2Json.xmltoJson(result2);
                        logger.info("****json2"+json2);
                        //{"Envelope":{"Body":{"SaveGjgHpvResponse":{"SaveGjgHpvResult":"{\"SUCCESS\":\"0\",\"MESSAGE\":\"0,父节点不能为空\",\"DATA\":[]}"}}}}
                        JSONObject envelopeObj2 = (JSONObject) json2.get("Envelope");
                        JSONObject bodyObj2 = (JSONObject) envelopeObj2.get("Body");
                        JSONObject saveGjgBsqkResponseObj2 = (JSONObject) bodyObj2.get("SaveGjgBsqkResponse");
                        JSONObject saveGjgBsqkResult2 =JSONObject.parseObject (String.valueOf( saveGjgBsqkResponseObj2.get("SaveGjgBsqkResult")));

                        String resultCode2 = saveGjgBsqkResult2.getString("SUCCESS");
                        String msg2 = saveGjgBsqkResult2.getString("MESSAGE");
                        if(!"1".equals(resultCode2))
                        {
                            logger.info("****接口：SaveGjgBsqk上传失败，"+msg2);
                            //更新 上传状态
                            HashMap updateparam  = new HashMap();
                            updateparam.put("peId",peId);
                            updateparam.put("visitid",visitid);
                            updateparam.put("idNo",idNo);
                            updateparam.put("sendOrderId",sendOrderId);
                            updateparam.put("tableName",tableName);
                            updateparam.put("uploadStatus","0");
                            if(msg2.length()>50){
                                updateparam.put("errMsg","接口：SaveGjgBsqk上传失败"+msg2.substring(0,50));
                            }
                            else
                            {
                                updateparam.put("errMsg","接口：SaveGjgBsqk上传失败"+msg2);
                            }

                            updateUploadStatus(updateparam);
                            continue;
                        }

                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","1");
                        updateparam.put("errMsg","succ");
                        updateUploadStatus(updateparam);

                        this.saveGjgFkjc(sendOrderId,"GJGFKJC",  peId,  visitid, idNo);
                    }
                }


            }catch (Exception e){
                e.printStackTrace();
            }
        }



        return resultMsg;
    }


    /**
     *
     * @param sendOrderId
     * @param tableName GJGXBXJC
     * @return
     */
    @RequestMapping("/saveGjgXbxjcMk")
    @ResponseBody
    public String saveGjgXbxjcMk(@RequestParam(value = "sendOrderId", required = true) String sendOrderId,
                             @RequestParam(value = "tableName", required = true) String tableName
    )
    {
        logger.info("*****宫颈癌细胞学检查孕前优生基本信息上传******开始调用【saveGjgXbxjcMk】");
        logger.info("****入参 批次:"+sendOrderId +",表名："+tableName);

        String resultMsg ="1";
        HashMap qryparam  = new HashMap();
        qryparam.put("sendOrderId",sendOrderId);
        qryparam.put("tableName",tableName);
        List<HashMap> uploadList = healthPatInfoService.queryUploadGjgXbxjc(qryparam);
        // List<HashMap> errList = new ArrayList<HashMap>();
        for (HashMap info:uploadList)
        {
            try {
                if (info != null) {
                    //  先用主索引接口 获取主索引 再上传病史生成 档案  再查询档案 上传对应检查后，QeuryGJAIDByIdNo 才会有记录
                    //查询 QeuryGJAIDByIdNo 接口，获取 pId与 personIndex
                    String peId = String.valueOf(info.get("PE_ID") == null ? "" : info.get("PE_ID"));
                    String visitid = String.valueOf(info.get("PE_VISIT_ID") == null ? "0" : info.get("PE_VISIT_ID"));
                    String idNo = String.valueOf(info.get("ID_NO") == null ? "" : info.get("ID_NO"));
                    logger.info("****身份证号："+idNo);
                    if ("".equals(idNo)) {
                        logger.info("****身份证号为空不能上传");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","身份证号为空不能上传");
                        updateUploadStatus(updateparam);
                        continue;
                    }

                    HashMap params1 = new HashMap();
                    params1.put("IdNo",idNo);
                    String tpl1 = ReadTpltoStr.readTol("tpl_QeuryGJAIDByIdNo.xml");
                    String tpl1ReqXml = fillParamsToTpl(tpl1,params1 );
                    logger.info("****入参:"+ tpl1ReqXml );
                    String result1 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl1ReqXml,_INFURL);
                    Thread.sleep(1000);
                    logger.info("****出参:"+result1);

                    if(result1==null ||"".equals(result1))
                    {
                        //errList.add(info);
                        logger.info("****接口：QeuryGJAIDByIdNo查询失败，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo查询失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json1 =  Xml2Json.xmltoJson(result1);
                    //{"Envelope":{"Body":{"QeuryGJAIDByIdNoResponse":{"QeuryGJAIDByIdNoResult":"{\"SUCCESS\":\"1\",\"MESSAGE\":\"\",\"DATA\":[]}"}}}}
                    JSONObject envelopeObj = (JSONObject) json1.get("Envelope");
                    JSONObject bodyObj = (JSONObject) envelopeObj.get("Body");
                    JSONObject qeuryGJAIDByIdNoResponseObj = (JSONObject) bodyObj.get("QeuryGJAIDByIdNoResponse");
                    JSONObject qeuryGJAIDByIdNoResultObj =JSONObject.parseObject (String.valueOf( qeuryGJAIDByIdNoResponseObj.get("QeuryGJAIDByIdNoResult")));

                    String resultCode1 = qeuryGJAIDByIdNoResultObj.getString("SUCCESS");
                    String msg1 = qeuryGJAIDByIdNoResultObj.getString("MESSAGE");
                    if(!"1".equals(resultCode1))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo查询失败，"+msg1);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg1.length()>50){
                            updateparam.put("errMsg","接口：saveGjgXbxjcMk上传失败"+msg1.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：saveGjgXbxjcMk上传失败"+msg1);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONArray data1arr = qeuryGJAIDByIdNoResultObj.getJSONArray("DATA");
                    if(data1arr==null || (data1arr!=null && data1arr.size()==0))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 返回结果中DATA为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
//{"SUCCESS":"1","MESSAGE":"","DATA":[{"PE_ID":"6407a78c-0c09-4fa9-926f-5aa2f04fa946","PERSON_INDEX":"073826501","ID_NO":"452128198307116045","YEAR_REPORTED":"2022","QUARTERLY_REPORTED":"3","BH":""}]}
//                    JSONObject data1Index0 = (JSONObject) data1arr.get(0);
//                    String pId = String.valueOf(data1Index0.get("PE_ID") == null ? "" : data1Index0.get("PE_ID"));
//                    String personIndex = String.valueOf(data1Index0.get("PERSON_INDEX") == null ? "" : data1Index0.get("PERSON_INDEX"));
                    String pId="";
                    String personIndex="";
                    //返回的数据有多条，要找到对应体检号这条
                    for (int i = 0; i < data1arr.size(); i++) {
                        JSONObject jsonObject = data1arr.getJSONObject(i);
                        String PE_ID = jsonObject.getString("PE_ID");
                        if (PE_ID.equals(peId+visitid)) {
                            pId = String.valueOf(jsonObject.get("PE_ID") == null ? "" : jsonObject.get("PE_ID"));
                            personIndex = String.valueOf(jsonObject.get("PERSON_INDEX") == null ? "" : jsonObject.get("PERSON_INDEX"));
                        }
                    }
                    logger.info("****接口：QeuryGJAIDByIdNo 返回结果中PId："+pId +",personIndex:"+personIndex);
                    if("".equals(pId))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA中：PE_ID为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 返回结果中DATA中：PE_ID为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    if("".equals(personIndex))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA中：person_index为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 返回结果中DATA中：person_index为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    //上报 SaveGjgHpv
                    HashMap params2 = new HashMap();

                    params2.put("peId",peId);
                    params2.put("visitid",visitid);

                    //上传的体检号=体检号+体检次数
                    String getPeId = peId + visitid;
                    params2.put("getPeId",getPeId);

                    params2.put("personIndex",personIndex);
                    params2.put("pId",pId);

                    //测试数据
                    // params2.put("personIndex","9999");
                    // params2.put("pId","TJ01937443");

                    String samplingMethods = String.valueOf(info.get("SAMPLING_METHODS") == null ? "" : info.get("SAMPLING_METHODS"));
                    params2.put("samplingMethods",samplingMethods);

                    String other = String.valueOf(info.get("OTHER") == null ? "" : info.get("OTHER"));
                    params2.put("other",other);

                    String papGrading = String.valueOf(info.get("PAPGRADING") == null ? "" : info.get("PAPGRADING"));
                    params2.put("papGrading",papGrading);

                    String intraepithelialLesions = String.valueOf(info.get("INTREAPITHELIAL_LESIONS") == null ? "" : info.get("INTREAPITHELIAL_LESIONS"));
                    params2.put("intraepithelialLesions",intraepithelialLesions);

                    String ascUs = String.valueOf(info.get("ASC_US") == null ? "" : info.get("ASC_US"));
                    params2.put("ascUs",ascUs);

                    String ascH = String.valueOf(info.get("ASC_H") == null ? "" : info.get("ASC_H"));
                    params2.put("ascH",ascH);

                    String lsil = String.valueOf(info.get("LSIL") == null ? "" : info.get("LSIL"));
                    params2.put("lsil",lsil);

                    String hsil = String.valueOf(info.get("HSIL") == null ? "" : info.get("HSIL"));
                    params2.put("hsil",hsil);

                    String scc = String.valueOf(info.get("SCC") == null ? "" : info.get("SCC"));
                    params2.put("scc",scc);

                    String agc = String.valueOf(info.get("AGC") == null ? "" : info.get("AGC"));
                    params2.put("agc",agc);

                    String atypicalEndocervical = String.valueOf(info.get("ATYPICAL_ENDOCERVICAL") == null ? "" : info.get("ATYPICAL_ENDOCERVICAL"));
                    params2.put("atypicalEndocervical",atypicalEndocervical);

                    String endocervicalCarcinoma = String.valueOf(info.get("ENDOCERVICAL_CARCINOMA") == null ? "" : info.get("ENDOCERVICAL_CARCINOMA"));
                    params2.put("endocervicalCarcinoma",endocervicalCarcinoma);

                    String adenocarcinoma = String.valueOf(info.get("ADENOCARCINOMA") == null ? "" : info.get("ADENOCARCINOMA"));
                    params2.put("adenocarcinoma",adenocarcinoma);

                    String colposcopy = String.valueOf(info.get("COLPOSCOPY") == null ? "" : info.get("COLPOSCOPY"));
                    params2.put("colposcopy",colposcopy);

                    String reportDatestr = String.valueOf(info.get("PE_DATE") == null ? "" : info.get("PE_DATE"));
                    String reportDate ="";
                    if(!("".equals(reportDatestr)))
                    {
                        reportDate = reportDatestr.substring(0,10);
                    }
                    params2.put("reportDate",reportDate);

                    String reportPerson = String.valueOf(info.get("DOCTOR_NAME") == null ? "" : info.get("DOCTOR_NAME"));
                    params2.put("reportPerson",reportPerson);

                    String inoutSign1 = String.valueOf(info.get("INOUTSIGN1") == null ? "0" : info.get("INOUTSIGN1"));
                    params2.put("inoutSign1",inoutSign1);

                    //
                    String tpl2 = ReadTpltoStr.readTol("tpl_SaveGjgXbxjcMk.xml");
                    String tpl2ReqXml = fillParamsToTpl(tpl2,params2 );
                    logger.info("****入参:"+ tpl2ReqXml );
                    String result2 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl2ReqXml,_INFURL);
                    logger.info("****出参:"+result2);

                    if(result2==null ||"".equals(result2))
                    {
                        // errList.add(info);
                        logger.info("****接口：SaveGjgXbxjcMk上传失败，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：SaveGjgXbxjcMk上传失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json2 =  Xml2Json.xmltoJson(result2);
                    logger.info("****json2"+json2);
                    JSONObject envelopeObj2 = (JSONObject) json2.get("Envelope");
                    JSONObject bodyObj2 = (JSONObject) envelopeObj2.get("Body");
                    JSONObject saveGjgXbxjcMkResponseObj2 = (JSONObject) bodyObj2.get("SaveGjgXbxjcMkResponse");
                    JSONObject saveGjgXbxjcMkResult2 =JSONObject.parseObject (String.valueOf( saveGjgXbxjcMkResponseObj2.get("SaveGjgXbxjcMkResult")));

                    String resultCode2 = saveGjgXbxjcMkResult2.getString("SUCCESS");
                    String msg2 = saveGjgXbxjcMkResult2.getString("MESSAGE");
                    if(!"1".equals(resultCode2))
                    {
                        logger.info("****接口：SaveGjgXbxjcMk上传失败，"+msg2);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg2.length()>50){
                            updateparam.put("errMsg","接口：SaveGjgXbxjcMk上传失败"+msg2.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：SaveGjgXbxjcMk上传失败"+msg2);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }

                    //更新 上传状态
                    HashMap updateparam  = new HashMap();
                    updateparam.put("peId",peId);
                    updateparam.put("visitid",visitid);
                    updateparam.put("idNo",idNo);
                    updateparam.put("sendOrderId",sendOrderId);
                    updateparam.put("tableName",tableName);
                    updateparam.put("uploadStatus","1");
                    updateparam.put("errMsg","succ");

                    updateUploadStatus(updateparam);

                }
            }catch (Exception e){
                //errList.add(info);
                e.printStackTrace();
            }
        }
        return resultMsg;
    }


    /**
     *
     * @param sendOrderId
     * @param tableName GJGYDJJC
     * @return
     */
    @RequestMapping("/saveGjgYdjjc")
    @ResponseBody
    public String saveGjgYdjjc(@RequestParam(value = "sendOrderId", required = true) String sendOrderId,
                                 @RequestParam(value = "tableName", required = true) String tableName
    )
    {
        logger.info("*****宫颈癌阴道镜检查******开始调用【saveGjgYdjjc】");
        logger.info("****入参 批次:"+sendOrderId +",表名："+tableName);

        String resultMsg ="1";
        HashMap qryparam  = new HashMap();
        qryparam.put("sendOrderId",sendOrderId);
        qryparam.put("tableName",tableName);
        List<HashMap> uploadList = healthPatInfoService.queryUploadGjgYdjjc(qryparam);
        // List<HashMap> errList = new ArrayList<HashMap>();
        for (HashMap info:uploadList)
        {
            try {
                if (info != null) {
                    //  先用主索引接口 获取主索引 再上传病史生成 档案  再查询档案 上传对应检查后，QeuryGJAIDByIdNo 才会有记录
                    //查询 QeuryGJAIDByIdNo 接口，获取 pId与 personIndex
                    String peId = String.valueOf(info.get("PE_ID") == null ? "" : info.get("PE_ID"));
                    String visitid = String.valueOf(info.get("PE_VISIT_ID") == null ? "0" : info.get("PE_VISIT_ID"));
                    String idNo = String.valueOf(info.get("ID_NO") == null ? "" : info.get("ID_NO"));
                    logger.info("****身份证号："+idNo);
                    if ("".equals(idNo)) {
                        logger.info("****身份证号为空不能上传");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","身份证号为空不能上传");
                        updateUploadStatus(updateparam);
                        continue;
                    }

                    HashMap params1 = new HashMap();
                    params1.put("IdNo",idNo);
                    String tpl1 = ReadTpltoStr.readTol("tpl_QeuryGJAIDByIdNo.xml");
                    String tpl1ReqXml = fillParamsToTpl(tpl1,params1 );
                    logger.info("****入参:"+ tpl1ReqXml );
                    String result1 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl1ReqXml,_INFURL);
                    logger.info("****出参:"+result1);

                    if(result1==null ||"".equals(result1))
                    {
                        //errList.add(info);
                        logger.info("****接口：QeuryGJAIDByIdNo查询失败，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo查询失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json1 =  Xml2Json.xmltoJson(result1);
                    //{"Envelope":{"Body":{"QeuryGJAIDByIdNoResponse":{"QeuryGJAIDByIdNoResult":"{\"SUCCESS\":\"1\",\"MESSAGE\":\"\",\"DATA\":[]}"}}}}
                    JSONObject envelopeObj = (JSONObject) json1.get("Envelope");
                    JSONObject bodyObj = (JSONObject) envelopeObj.get("Body");
                    JSONObject qeuryGJAIDByIdNoResponseObj = (JSONObject) bodyObj.get("QeuryGJAIDByIdNoResponse");
                    JSONObject qeuryGJAIDByIdNoResultObj =JSONObject.parseObject (String.valueOf( qeuryGJAIDByIdNoResponseObj.get("QeuryGJAIDByIdNoResult")));

                    String resultCode1 = qeuryGJAIDByIdNoResultObj.getString("SUCCESS");
                    String msg1 = qeuryGJAIDByIdNoResultObj.getString("MESSAGE");
                    if(!"1".equals(resultCode1))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo查询失败，"+msg1);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg1.length()>50){
                            updateparam.put("errMsg","接口：saveGjgXbxjcMk上传失败"+msg1.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：saveGjgXbxjcMk上传失败"+msg1);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONArray data1arr = qeuryGJAIDByIdNoResultObj.getJSONArray("DATA");
                    if(data1arr==null || (data1arr!=null && data1arr.size()==0))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 返回结果中DATA为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
//{"SUCCESS":"1","MESSAGE":"","DATA":[{"PE_ID":"6407a78c-0c09-4fa9-926f-5aa2f04fa946","PERSON_INDEX":"073826501","ID_NO":"452128198307116045","YEAR_REPORTED":"2022","QUARTERLY_REPORTED":"3","BH":""}]}
//                    JSONObject data1Index0 = (JSONObject) data1arr.get(0);
//                    String pId = String.valueOf(data1Index0.get("PE_ID") == null ? "" : data1Index0.get("PE_ID"));
//                    String personIndex = String.valueOf(data1Index0.get("PERSON_INDEX") == null ? "" : data1Index0.get("PERSON_INDEX"));
                    String pId="";
                    String personIndex="";
                    //返回的数据有多条，要找到对应体检号这条
                    for (int i = 0; i < data1arr.size(); i++) {
                        JSONObject jsonObject = data1arr.getJSONObject(i);
                        String PE_ID = jsonObject.getString("PE_ID");
                        if (PE_ID.equals(peId+visitid)) {
                            pId = String.valueOf(jsonObject.get("PE_ID") == null ? "" : jsonObject.get("PE_ID"));
                            personIndex = String.valueOf(jsonObject.get("PERSON_INDEX") == null ? "" : jsonObject.get("PERSON_INDEX"));
                        }
                    }
                    logger.info("****接口：QeuryGJAIDByIdNo 返回结果中PId："+pId +",personIndex:"+personIndex);
                    if("".equals(pId))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA中：PE_ID为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 返回结果中DATA中：PE_ID为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    if("".equals(personIndex))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA中：person_index为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 返回结果中DATA中：person_index为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    //上报 SaveGjgHpv
                    HashMap params2 = new HashMap();

                    params2.put("peId",peId);
                    params2.put("visitid",visitid);

                    //上传的体检号=体检号+体检次数
                    String getPeId = peId + visitid;
                    params2.put("getPeId",getPeId);

                    params2.put("personIndex",personIndex);
                    params2.put("pId",pId);

                    //测试数据
                    // params2.put("personIndex","9999");
                    // params2.put("pId","TJ01937443");

                    String colposcopy = String.valueOf(info.get("COLPOSCOPY") == null ? "" : info.get("COLPOSCOPY"));
                    params2.put("colposcopy",colposcopy);

                    String colposcopyEvaluation = String.valueOf(info.get("COLPOSCOPY_EVALUATION") == null ? "" : info.get("COLPOSCOPY_EVALUATION"));
                    params2.put("colposcopyEvaluation",colposcopyEvaluation);

                    String histopathologicalExamination = String.valueOf(info.get("HISTOPATHOLOGICAL_EXAMINATION") == null ? "" : info.get("HISTOPATHOLOGICAL_EXAMINATION"));
                    params2.put("histopathologicalExamination",histopathologicalExamination);


                    String inoutSign1 = String.valueOf(info.get("INOUTSIGN1") == null ? "0" : info.get("INOUTSIGN1"));
                    params2.put("inoutSign1",inoutSign1);

                    String reportPerson = String.valueOf(info.get("DOCTOR_NAME") == null ? "" : info.get("DOCTOR_NAME"));
                    params2.put("reportPerson",reportPerson);

                    String reportDatestr = String.valueOf(info.get("PE_DATE") == null ? "" : info.get("PE_DATE"));
                    String checkDate ="";
                    if(!("".equals(reportDatestr)))
                    {
                        checkDate = reportDatestr.substring(0,10);
                    }
                    params2.put("checkDate",checkDate);


                    String preliminaryDiagnosis = String.valueOf(info.get("PRELIMINARY_DIAGNOSIS") == null ? "" : info.get("PRELIMINARY_DIAGNOSIS"));
                    params2.put("preliminaryDiagnosis",preliminaryDiagnosis);

                    //
                    String tpl2 = ReadTpltoStr.readTol("tpl_SaveGjgYdjjc.xml");
                    String tpl2ReqXml = fillParamsToTpl(tpl2,params2 );
                    logger.info("****入参:"+ tpl2ReqXml );
                    String result2 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl2ReqXml,_INFURL);
                    logger.info("****出参:"+result2);

                    if(result2==null ||"".equals(result2))
                    {
                        // errList.add(info);
                        logger.info("****接口：SaveGjgYdjjc，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：SaveGjgYdjjc上传失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json2 =  Xml2Json.xmltoJson(result2);
                    logger.info("****json2"+json2);
                    JSONObject envelopeObj2 = (JSONObject) json2.get("Envelope");
                    JSONObject bodyObj2 = (JSONObject) envelopeObj2.get("Body");
                    JSONObject saveGjgYdjjcResponseObj2 = (JSONObject) bodyObj2.get("SaveGjgYdjjcResponse");
                    JSONObject saveGjgYdjjcResult2 =JSONObject.parseObject (String.valueOf( saveGjgYdjjcResponseObj2.get("SaveGjgYdjjcResult")));

                    String resultCode2 = saveGjgYdjjcResult2.getString("SUCCESS");
                    String msg2 = saveGjgYdjjcResult2.getString("MESSAGE");
                    if(!"1".equals(resultCode2))
                    {
                        logger.info("****接口：SaveGjgYdjjc上传失败，"+msg2);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg2.length()>50){
                            updateparam.put("errMsg","接口：SaveGjgYdjjc上传失败"+msg2.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：SaveGjgYdjjc上传失败"+msg2);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }

                    //更新 上传状态
                    HashMap updateparam  = new HashMap();
                    updateparam.put("peId",peId);
                    updateparam.put("visitid",visitid);
                    updateparam.put("idNo",idNo);
                    updateparam.put("sendOrderId",sendOrderId);
                    updateparam.put("tableName",tableName);
                    updateparam.put("uploadStatus","1");
                    updateparam.put("errMsg","succ");
                    updateUploadStatus(updateparam);

                }
            }catch (Exception e){
                //errList.add(info);
                e.printStackTrace();
            }
        }
        return resultMsg;
    }

    /**
     *
     * @param sendOrderId
     * @param tableName GJGZZXJC
     * @return
     */
    @RequestMapping("/saveGjgZzxjc")
    @ResponseBody
    public String saveGjgZzxjc(@RequestParam(value = "sendOrderId", required = true) String sendOrderId,
                               @RequestParam(value = "tableName", required = true) String tableName
    )
    {
        logger.info("*****宫颈癌病理学检查******开始调用【saveGjgZzxjc】");
        logger.info("****入参 批次:"+sendOrderId +",表名："+tableName);

        String resultMsg ="1";
        HashMap qryparam  = new HashMap();
        qryparam.put("sendOrderId",sendOrderId);
        qryparam.put("tableName",tableName);
        List<HashMap> uploadList = healthPatInfoService.queryUploadGjgZzxjc(qryparam);
        // List<HashMap> errList = new ArrayList<HashMap>();
        for (HashMap info:uploadList)
        {
            try {
                if (info != null) {
                    //  先用主索引接口 获取主索引 再上传病史生成 档案  再查询档案 上传对应检查后，QeuryGJAIDByIdNo 才会有记录
                    //查询 QeuryGJAIDByIdNo 接口，获取 pId与 personIndex
                    String peId = String.valueOf(info.get("PE_ID") == null ? "" : info.get("PE_ID"));
                    String visitid = String.valueOf(info.get("PE_VISIT_ID") == null ? "0" : info.get("PE_VISIT_ID"));
                    String idNo = String.valueOf(info.get("ID_NO") == null ? "" : info.get("ID_NO"));
                    logger.info("****身份证号："+idNo);
                    if ("".equals(idNo)) {
                        logger.info("****身份证号为空不能上传");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","身份证号为空不能上传");
                        updateUploadStatus(updateparam);
                        continue;
                    }

                    HashMap params1 = new HashMap();
                    params1.put("IdNo",idNo);
                    String tpl1 = ReadTpltoStr.readTol("tpl_QeuryGJAIDByIdNo.xml");
                    String tpl1ReqXml = fillParamsToTpl(tpl1,params1 );
                    logger.info("****入参:"+ tpl1ReqXml );
                    String result1 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl1ReqXml,_INFURL);
                    logger.info("****出参:"+result1);

                    if(result1==null ||"".equals(result1))
                    {
                        //errList.add(info);
                        logger.info("****接口：QeuryGJAIDByIdNo查询失败，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo查询失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json1 =  Xml2Json.xmltoJson(result1);
                    //{"Envelope":{"Body":{"QeuryGJAIDByIdNoResponse":{"QeuryGJAIDByIdNoResult":"{\"SUCCESS\":\"1\",\"MESSAGE\":\"\",\"DATA\":[]}"}}}}
                    JSONObject envelopeObj = (JSONObject) json1.get("Envelope");
                    JSONObject bodyObj = (JSONObject) envelopeObj.get("Body");
                    JSONObject qeuryGJAIDByIdNoResponseObj = (JSONObject) bodyObj.get("QeuryGJAIDByIdNoResponse");
                    JSONObject qeuryGJAIDByIdNoResultObj =JSONObject.parseObject (String.valueOf( qeuryGJAIDByIdNoResponseObj.get("QeuryGJAIDByIdNoResult")));

                    String resultCode1 = qeuryGJAIDByIdNoResultObj.getString("SUCCESS");
                    String msg1 = qeuryGJAIDByIdNoResultObj.getString("MESSAGE");
                    if(!"1".equals(resultCode1))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo查询失败，"+msg1);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg1.length()>50){
                            updateparam.put("errMsg","接口：saveGjgZzxjc上传失败"+msg1.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：saveGjgZzxjc上传失败"+msg1);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONArray data1arr = qeuryGJAIDByIdNoResultObj.getJSONArray("DATA");
                    if(data1arr==null || (data1arr!=null && data1arr.size()==0))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 返回结果中DATA为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
//{"SUCCESS":"1","MESSAGE":"","DATA":[{"PE_ID":"6407a78c-0c09-4fa9-926f-5aa2f04fa946","PERSON_INDEX":"073826501","ID_NO":"452128198307116045","YEAR_REPORTED":"2022","QUARTERLY_REPORTED":"3","BH":""}]}
//                    JSONObject data1Index0 = (JSONObject) data1arr.get(0);
//                    String pId = String.valueOf(data1Index0.get("PE_ID") == null ? "" : data1Index0.get("PE_ID"));
//                    String personIndex = String.valueOf(data1Index0.get("PERSON_INDEX") == null ? "" : data1Index0.get("PERSON_INDEX"));
                    String pId="";
                    String personIndex="";
                    //返回的数据有多条，要找到对应体检号这条
                    for (int i = 0; i < data1arr.size(); i++) {
                        JSONObject jsonObject = data1arr.getJSONObject(i);
                        String PE_ID = jsonObject.getString("PE_ID");
                        if (PE_ID.equals(peId+visitid)) {
                            pId = String.valueOf(jsonObject.get("PE_ID") == null ? "" : jsonObject.get("PE_ID"));
                            personIndex = String.valueOf(jsonObject.get("PERSON_INDEX") == null ? "" : jsonObject.get("PERSON_INDEX"));
                        }
                    }
                    logger.info("****接口：QeuryGJAIDByIdNo 返回结果中PId："+pId +",personIndex:"+personIndex);
                    if("".equals(pId))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA中：PE_ID为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 返回结果中DATA中：PE_ID为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    if("".equals(personIndex))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA中：person_index为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 返回结果中DATA中：person_index为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    //上报  saveGjgZzxjc
                    HashMap params2 = new HashMap();

                    params2.put("peId",peId);
                    params2.put("visitid",visitid);

                    //上传的体检号=体检号+体检次数
                    String getPeId = peId + visitid;
                    params2.put("getPeId",getPeId);

                    params2.put("personIndex",personIndex);
                    params2.put("pId",pId);

                    //测试数据
                    // params2.put("personIndex","9999");
                    // params2.put("pId","TJ01937443");

                    String histopathologicalFindings = String.valueOf(info.get("HISTOPATHOLOGICAL_FINDINGS") == null ? "" : info.get("HISTOPATHOLOGICAL_FINDINGS"));
                    params2.put("histopathologicalFindings",histopathologicalFindings);

                    String inflammation = String.valueOf(info.get("INFLAMMATION") == null ? "" : info.get("INFLAMMATION"));
                    params2.put("inflammation",inflammation);

                    String lsil1 = String.valueOf(info.get("LSIL1") == null ? "" : info.get("LSIL1"));
                    params2.put("lsil1",lsil1);

                    String hsil1 = String.valueOf(info.get("HSIL1") == null ? "" : info.get("HSIL1"));
                    params2.put("hsil1",hsil1);


                    String ais = String.valueOf(info.get("AIS") == null ? "" : info.get("AIS"));
                    params2.put("ais",ais);

                    String microinvasiveSquamous = String.valueOf(info.get("MICROINVASIVE_SQUAMOUS") == null ? "" : info.get("MICROINVASIVE_SQUAMOUS"));
                    params2.put("microinvasiveSquamous",microinvasiveSquamous);

                    String invasiveCarcinoma = String.valueOf(info.get("INVASIVE_CARCINOMA") == null ? "" : info.get("INVASIVE_CARCINOMA"));
                    params2.put("invasiveCarcinoma",invasiveCarcinoma);

                    String zzblxjcjgycqk = String.valueOf(info.get("ZZBLXJCJGYCQK") == null ? "" : info.get("ZZBLXJCJGYCQK"));
                    params2.put("zzblxjcjgycqk",zzblxjcjgycqk);



                    String inoutSign1 = String.valueOf(info.get("INOUTSIGN1") == null ? "0" : info.get("INOUTSIGN1"));
                    params2.put("inoutSign1",inoutSign1);

                    String reportPerson = String.valueOf(info.get("REPORT_PERSON") == null ? "" : info.get("REPORT_PERSON"));
                    params2.put("reportPerson",reportPerson);

                    String reportDatestr = String.valueOf(info.get("DIAGNOSTIC_DATE") == null ? "" : info.get("DIAGNOSTIC_DATE"));
                    String diagnosticDate ="";
                    if(!("".equals(reportDatestr)))
                    {
                        diagnosticDate = reportDatestr.substring(0,10);
                    }
                    params2.put("diagnosticDate",diagnosticDate);


                    String tpl2 = ReadTpltoStr.readTol("tpl_SaveGjgZzxjc.xml");
                    String tpl2ReqXml = fillParamsToTpl(tpl2,params2 );
                    logger.info("****入参:"+ tpl2ReqXml );
                    String result2 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl2ReqXml,_INFURL);
                    logger.info("****出参:"+result2);

                    if(result2==null ||"".equals(result2))
                    {
                        // errList.add(info);
                        logger.info("****接口：SaveGjgZzxjc，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：SaveGjgZzxjc上传失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json2 =  Xml2Json.xmltoJson(result2);
                    logger.info("****json2"+json2);
                    JSONObject envelopeObj2 = (JSONObject) json2.get("Envelope");
                    JSONObject bodyObj2 = (JSONObject) envelopeObj2.get("Body");
                    JSONObject saveGjgZzxjcResponseObj2 = (JSONObject) bodyObj2.get("SaveGjgZzxjcResponse");
                    JSONObject saveGjgZzxjcResult2 =JSONObject.parseObject (String.valueOf( saveGjgZzxjcResponseObj2.get("SaveGjgZzxjcResult")));

                    String resultCode2 = saveGjgZzxjcResult2.getString("SUCCESS");
                    String msg2 = saveGjgZzxjcResult2.getString("MESSAGE");
                    if(!"1".equals(resultCode2))
                    {
                        logger.info("****接口：SaveGjgZzxjc上传失败，"+msg2);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg2.length()>50){
                            updateparam.put("errMsg","接口：SaveGjgZzxjc上传失败"+msg2.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：SaveGjgZzxjc上传失败"+msg2);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }

                    //更新 上传状态
                    HashMap updateparam  = new HashMap();
                    updateparam.put("peId",peId);
                    updateparam.put("visitid",visitid);
                    updateparam.put("idNo",idNo);
                    updateparam.put("sendOrderId",sendOrderId);
                    updateparam.put("tableName",tableName);
                    updateparam.put("uploadStatus","1");
                    updateparam.put("errMsg","succ");
                    updateUploadStatus(updateparam);

                }
            }catch (Exception e){
                //errList.add(info);
                e.printStackTrace();
            }
        }
        return resultMsg;
    }

    /**
     *
     * @param sendOrderId
     * @param tableName  GJGZHZD
     * @return
     */
    @RequestMapping("/saveGjgZhzd")
    @ResponseBody
    public String saveGjgZhzd(@RequestParam(value = "sendOrderId", required = true) String sendOrderId,
                               @RequestParam(value = "tableName", required = true) String tableName
    )
    {
        logger.info("*****宫颈癌最后诊断 ******开始调用【saveGjgZhzd】");
        logger.info("****入参 批次:"+sendOrderId +",表名："+tableName);

        String resultMsg ="1";
        HashMap qryparam  = new HashMap();
        qryparam.put("sendOrderId",sendOrderId);
        qryparam.put("tableName",tableName);
        List<HashMap> uploadList = healthPatInfoService.queryUploadGjgZhzd(qryparam);
        // List<HashMap> errList = new ArrayList<HashMap>();
        for (HashMap info:uploadList)
        {
            try {
                if (info != null) {
                    //  先用主索引接口 获取主索引 再上传病史生成 档案  再查询档案 上传对应检查后，QeuryGJAIDByIdNo 才会有记录
                    //查询 QeuryGJAIDByIdNo 接口，获取 pId与 personIndex
                    String peId = String.valueOf(info.get("PE_ID") == null ? "" : info.get("PE_ID"));
                    String visitid = String.valueOf(info.get("PE_VISIT_ID") == null ? "0" : info.get("PE_VISIT_ID"));
                    String idNo = String.valueOf(info.get("ID_NO") == null ? "" : info.get("ID_NO"));
                    logger.info("****身份证号："+idNo);
                    if ("".equals(idNo)) {
                        logger.info("****身份证号为空不能上传");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","身份证号为空不能上传");
                        updateUploadStatus(updateparam);
                        continue;
                    }

                    HashMap params1 = new HashMap();
                    params1.put("IdNo",idNo);
                    String tpl1 = ReadTpltoStr.readTol("tpl_QeuryGJAIDByIdNo.xml");
                    String tpl1ReqXml = fillParamsToTpl(tpl1,params1 );
                    logger.info("****入参:"+ tpl1ReqXml );
                    String result1 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl1ReqXml,_INFURL);
                    logger.info("****出参:"+result1);

                    if(result1==null ||"".equals(result1))
                    {
                        //errList.add(info);
                        logger.info("****接口：QeuryGJAIDByIdNo查询失败，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo查询失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json1 =  Xml2Json.xmltoJson(result1);
                    //{"Envelope":{"Body":{"QeuryGJAIDByIdNoResponse":{"QeuryGJAIDByIdNoResult":"{\"SUCCESS\":\"1\",\"MESSAGE\":\"\",\"DATA\":[]}"}}}}
                    JSONObject envelopeObj = (JSONObject) json1.get("Envelope");
                    JSONObject bodyObj = (JSONObject) envelopeObj.get("Body");
                    JSONObject qeuryGJAIDByIdNoResponseObj = (JSONObject) bodyObj.get("QeuryGJAIDByIdNoResponse");
                    JSONObject qeuryGJAIDByIdNoResultObj =JSONObject.parseObject (String.valueOf( qeuryGJAIDByIdNoResponseObj.get("QeuryGJAIDByIdNoResult")));

                    String resultCode1 = qeuryGJAIDByIdNoResultObj.getString("SUCCESS");
                    String msg1 = qeuryGJAIDByIdNoResultObj.getString("MESSAGE");
                    if(!"1".equals(resultCode1))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo查询失败，"+msg1);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg1.length()>50){
                            updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 失败"+msg1.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 失败"+msg1);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONArray data1arr = qeuryGJAIDByIdNoResultObj.getJSONArray("DATA");
                    if(data1arr==null || (data1arr!=null && data1arr.size()==0))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 返回结果中DATA为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
//{"SUCCESS":"1","MESSAGE":"","DATA":[{"PE_ID":"6407a78c-0c09-4fa9-926f-5aa2f04fa946","PERSON_INDEX":"073826501","ID_NO":"452128198307116045","YEAR_REPORTED":"2022","QUARTERLY_REPORTED":"3","BH":""}]}
                    JSONObject data1Index0 = (JSONObject) data1arr.get(0);
                    String pId = String.valueOf(data1Index0.get("PE_ID") == null ? "" : data1Index0.get("PE_ID"));
                    String personIndex = String.valueOf(data1Index0.get("PERSON_INDEX") == null ? "" : data1Index0.get("PERSON_INDEX"));
                    logger.info("****接口：QeuryGJAIDByIdNo 返回结果中PId："+pId +",personIndex:"+personIndex);
                    if("".equals(pId))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA中：PE_ID为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 返回结果中DATA中：PE_ID为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    if("".equals(personIndex))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA中：person_index为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 返回结果中DATA中：person_index为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    //上报  saveGjgZzxjc
                    HashMap params2 = new HashMap();

                    params2.put("peId",peId);
                    params2.put("visitid",visitid);

                    //上传的体检号=体检号+体检次数
                    String getPeId = peId + visitid;
                    params2.put("getPeId",getPeId);

                    params2.put("personIndex",personIndex);
                    params2.put("pId",pId);

                    //测试数据
                    // params2.put("personIndex","9999");
                    // params2.put("pId","TJ01937443");

                    String finalDiagnosis = String.valueOf(info.get("FINAL_DIAGNOSIS") == null ? "" : info.get("FINAL_DIAGNOSIS"));
                    params2.put("finalDiagnosis",finalDiagnosis);

                    String histopathologicalFindings = String.valueOf(info.get("HISTOPATHOLOGICAL_FIDINGS") == null ? "" : info.get("HISTOPATHOLOGICAL_FIDINGS"));
                    params2.put("histopathologicalFindings",histopathologicalFindings);

                    String trichomonasVaginitis = String.valueOf(info.get("TRICHOMONAS_VAGINITIS") == null ? "" : info.get("TRICHOMONAS_VAGINITIS"));
                    params2.put("trichomonasVaginitis",trichomonasVaginitis);

                    String vulvovaginalCandidiasis = String.valueOf(info.get("VULVOVAGINAL_CANDIDIASIS") == null ? "" : info.get("VULVOVAGINAL_CANDIDIASIS"));
                    params2.put("vulvovaginalCandidiasis",vulvovaginalCandidiasis);


                    String bacterialVaginosis = String.valueOf(info.get("BACTERIAL_VAGINOSIS") == null ? "" : info.get("BACTERIAL_VAGINOSIS"));
                    params2.put("bacterialVaginosis",bacterialVaginosis);

                    String condylomaAcuminatum = String.valueOf(info.get("CONDYLOMA_ACUMINATUM") == null ? "" : info.get("CONDYLOMA_ACUMINATUM"));
                    params2.put("condylomaAcuminatum",condylomaAcuminatum);

                    String fibroid = String.valueOf(info.get("FIBROID") == null ? "" : info.get("FIBROID"));
                    params2.put("fibroid",fibroid);

                    String mucopurulentCervicitis = String.valueOf(info.get("MUCOPURULENT_CERVICITIS") == null ? "" : info.get("MUCOPURULENT_CERVICITIS"));
                    params2.put("mucopurulentCervicitis",mucopurulentCervicitis);

                    String cervicalPolyp = String.valueOf(info.get("CERVICAL_POLYP") == null ? "" : info.get("CERVICAL_POLYP"));
                    params2.put("cervicalPolyp",cervicalPolyp);

                    String otherMalignancies = String.valueOf(info.get("OTHER_MALIGNANCIES") == null ? "" : info.get("OTHER_MALIGNANCIES"));
                    params2.put("otherMalignancies",otherMalignancies);

                    String otherBenignDiseases = String.valueOf(info.get("OTHER_BENIGN_DISEASES") == null ? "" : info.get("OTHER_BENIGN_DISEASES"));
                    params2.put("otherBenignDiseases",otherBenignDiseases);

                    String unknown = String.valueOf(info.get("UNKNOWN") == null ? "" : info.get("UNKNOWN"));
                    params2.put("unknown",unknown);

                    String inoutSign1 = String.valueOf(info.get("INOUTSIGN1") == null ? "0" : info.get("INOUTSIGN1"));
                    params2.put("inoutSign1",inoutSign1);

                    String diagnosticPerson = String.valueOf(info.get("REPORT_PERSON") == null ? "" : info.get("REPORT_PERSON"));
                    params2.put("diagnosticPerson",diagnosticPerson);

                    String reportDatestr = String.valueOf(info.get("DIAGNOSTIC_DATE") == null ? "" : info.get("DIAGNOSTIC_DATE"));
                    String diagnosticDate ="";
                    if(!("".equals(reportDatestr)))
                    {
                        diagnosticDate = reportDatestr.substring(0,10);
                    }
                    params2.put("diagnosticDate",diagnosticDate);


                    String tpl2 = ReadTpltoStr.readTol("tpl_SaveGjgZhzd.xml");
                    String tpl2ReqXml = fillParamsToTpl(tpl2,params2 );
                    logger.info("****入参:"+ tpl2ReqXml );
                    String result2 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl2ReqXml,_INFURL);
                    logger.info("****出参:"+result2);

                    if(result2==null ||"".equals(result2))
                    {
                        // errList.add(info);
                        logger.info("****接口：SaveGjgZhzd，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：SaveGjgZhzd上传失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json2 =  Xml2Json.xmltoJson(result2);
                    logger.info("****json2"+json2);
                    JSONObject envelopeObj2 = (JSONObject) json2.get("Envelope");
                    JSONObject bodyObj2 = (JSONObject) envelopeObj2.get("Body");
                    JSONObject saveGjgZhzdResponseObj2 = (JSONObject) bodyObj2.get("SaveGjgZhzdResponse");
                    JSONObject saveGjgZhzdResult2 =JSONObject.parseObject (String.valueOf( saveGjgZhzdResponseObj2.get("SaveGjgZhzdResult")));

                    String resultCode2 = saveGjgZhzdResult2.getString("SUCCESS");
                    String msg2 = saveGjgZhzdResult2.getString("MESSAGE");
                    if(!"1".equals(resultCode2))
                    {
                        logger.info("****接口：SaveGjgZhzd上传失败，"+msg2);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg2.length()>50){
                            updateparam.put("errMsg","接口：SaveGjgZhzd上传失败"+msg2.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：SaveGjgZhzd上传失败"+msg2);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }

                    //更新 上传状态
                    HashMap updateparam  = new HashMap();
                    updateparam.put("peId",peId);
                    updateparam.put("visitid",visitid);
                    updateparam.put("idNo",idNo);
                    updateparam.put("sendOrderId",sendOrderId);
                    updateparam.put("tableName",tableName);
                    updateparam.put("uploadStatus","1");
                    updateparam.put("errMsg","succ");
                    updateUploadStatus(updateparam);

                }
            }catch (Exception e){
                //errList.add(info);
                e.printStackTrace();
            }
        }
        return resultMsg;
    }



    /**
     *
     * @param sendOrderId
     * @param tableName  GJGSF
     * @return
     */
    @RequestMapping("/saveGjgZhsf")
    @ResponseBody
    public String saveGjgZhsf(@RequestParam(value = "sendOrderId", required = true) String sendOrderId,
                              @RequestParam(value = "tableName", required = true) String tableName
    )
    {
        logger.info("*****宫颈癌最后随访 ******开始调用【saveGjgZhsf】");
        logger.info("****入参 批次:"+sendOrderId +",表名："+tableName);

        String resultMsg ="1";
        HashMap qryparam  = new HashMap();
        qryparam.put("sendOrderId",sendOrderId);
        qryparam.put("tableName",tableName);
        List<HashMap> uploadList = healthPatInfoService.queryUploadGjgZhsf(qryparam);
        // List<HashMap> errList = new ArrayList<HashMap>();
        for (HashMap info:uploadList)
        {
            try {
                if (info != null) {
                    //  先用主索引接口 获取主索引 再上传病史生成 档案  再查询档案 上传对应检查后，QeuryGJAIDByIdNo 才会有记录
                    //查询 QeuryGJAIDByIdNo 接口，获取 pId与 personIndex
                    String peId = String.valueOf(info.get("PE_ID") == null ? "" : info.get("PE_ID"));
                    String visitid = String.valueOf(info.get("PE_VISIT_ID") == null ? "0" : info.get("PE_VISIT_ID"));
                    String idNo = String.valueOf(info.get("ID_NO") == null ? "" : info.get("ID_NO"));
                    logger.info("****身份证号："+idNo);
                    if ("".equals(idNo)) {
                        logger.info("****身份证号为空不能上传");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","身份证号为空不能上传");
                        updateUploadStatus(updateparam);
                        continue;
                    }

                    HashMap params1 = new HashMap();
                    params1.put("IdNo",idNo);
                    String tpl1 = ReadTpltoStr.readTol("tpl_QeuryGJAIDByIdNo.xml");
                    String tpl1ReqXml = fillParamsToTpl(tpl1,params1 );
                    logger.info("****入参:"+ tpl1ReqXml );
                    String result1 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl1ReqXml,_INFURL);
                    logger.info("****出参:"+result1);

                    if(result1==null ||"".equals(result1))
                    {
                        //errList.add(info);
                        logger.info("****接口：QeuryGJAIDByIdNo查询失败，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo查询失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json1 =  Xml2Json.xmltoJson(result1);
                    //{"Envelope":{"Body":{"QeuryGJAIDByIdNoResponse":{"QeuryGJAIDByIdNoResult":"{\"SUCCESS\":\"1\",\"MESSAGE\":\"\",\"DATA\":[]}"}}}}
                    JSONObject envelopeObj = (JSONObject) json1.get("Envelope");
                    JSONObject bodyObj = (JSONObject) envelopeObj.get("Body");
                    JSONObject qeuryGJAIDByIdNoResponseObj = (JSONObject) bodyObj.get("QeuryGJAIDByIdNoResponse");
                    JSONObject qeuryGJAIDByIdNoResultObj =JSONObject.parseObject (String.valueOf( qeuryGJAIDByIdNoResponseObj.get("QeuryGJAIDByIdNoResult")));

                    String resultCode1 = qeuryGJAIDByIdNoResultObj.getString("SUCCESS");
                    String msg1 = qeuryGJAIDByIdNoResultObj.getString("MESSAGE");
                    if(!"1".equals(resultCode1))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo查询失败，"+msg1);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg1.length()>50){
                            updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 失败"+msg1.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 失败"+msg1);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONArray data1arr = qeuryGJAIDByIdNoResultObj.getJSONArray("DATA");
                    if(data1arr==null || (data1arr!=null && data1arr.size()==0))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 返回结果中DATA为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
//{"SUCCESS":"1","MESSAGE":"","DATA":[{"PE_ID":"6407a78c-0c09-4fa9-926f-5aa2f04fa946","PERSON_INDEX":"073826501","ID_NO":"452128198307116045","YEAR_REPORTED":"2022","QUARTERLY_REPORTED":"3","BH":""}]}
//                    JSONObject data1Index0 = (JSONObject) data1arr.get(0);
//                    String pId = String.valueOf(data1Index0.get("PE_ID") == null ? "" : data1Index0.get("PE_ID"));
//                    String personIndex = String.valueOf(data1Index0.get("PERSON_INDEX") == null ? "" : data1Index0.get("PERSON_INDEX"));
                    String pId="";
                    String personIndex="";
                    //返回的数据有多条，要找到对应体检号这条
                    for (int i = 0; i < data1arr.size(); i++) {
                        JSONObject jsonObject = data1arr.getJSONObject(i);
                        String PE_ID = jsonObject.getString("PE_ID");
                        if (PE_ID.equals(peId+visitid)) {
                            pId = String.valueOf(jsonObject.get("PE_ID") == null ? "" : jsonObject.get("PE_ID"));
                            personIndex = String.valueOf(jsonObject.get("PERSON_INDEX") == null ? "" : jsonObject.get("PERSON_INDEX"));
                        }
                    }
                    logger.info("****接口：QeuryGJAIDByIdNo 返回结果中PId："+pId +",personIndex:"+personIndex);
                    if("".equals(pId))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA中：PE_ID为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 返回结果中DATA中：PE_ID为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    if("".equals(personIndex))
                    {
                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA中：person_index为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryGJAIDByIdNo 返回结果中DATA中：person_index为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    //上报
                    HashMap params2 = new HashMap();

                    params2.put("peId",peId);
                    params2.put("visitid",visitid);

                    //上传的体检号=体检号+体检次数
                    String getPeId = peId + visitid;
                    params2.put("getPeId",getPeId);

                    params2.put("personIndex",personIndex);
                    params2.put("pId",pId);

                    //测试数据
                    // params2.put("personIndex","9999");
                    // params2.put("pId","TJ01937443");

                    String cervicalLesionsFollowed = String.valueOf(info.get("CERVICAL_LESIONS_FOLLOWED") == null ? "" : info.get("CERVICAL_LESIONS_FOLLOWED"));
                    params2.put("cervicalLesionsFollowed",cervicalLesionsFollowed);

                    String cervicalLesionsTreatment = String.valueOf(info.get("CERVICAL_LESIONS_TREATMENT") == null ? "" : info.get("CERVICAL_LESIONS_TREATMENT"));
                    params2.put("cervicalLesionsTreatment",cervicalLesionsTreatment);

                    String otherTumorsFollow = String.valueOf(info.get("OTHER_TUMORS_FOLLOW") == null ? "" : info.get("OTHER_TUMORS_FOLLOW"));
                    params2.put("otherTumorsFollow",otherTumorsFollow);

                    String otherTumorsTreated = String.valueOf(info.get("OTHER_TUMORS_TREATED") == null ? "" : info.get("OTHER_TUMORS_TREATED"));
                    params2.put("otherTumorsTreated",otherTumorsTreated);



                    String inoutSign1 = String.valueOf(info.get("INOUTSIGN1") == null ? "0" : info.get("INOUTSIGN1"));
                    params2.put("inoutSign1",inoutSign1);

                    String followPerson = String.valueOf(info.get("FOLLOW_PERSON") == null ? "" : info.get("FOLLOW_PERSON"));
                    params2.put("followPerson",followPerson);

                    String reportDatestr = String.valueOf(info.get("FOLLOW_DATE") == null ? "" : info.get("FOLLOW_DATE"));
                    String followDate ="";
                    if(!("".equals(reportDatestr)))
                    {
                        followDate = reportDatestr.substring(0,10);
                    }
                    params2.put("followDate",followDate);


                    String tpl2 = ReadTpltoStr.readTol("tpl_SaveGjgZhsf.xml");
                    String tpl2ReqXml = fillParamsToTpl(tpl2,params2 );
                    logger.info("****入参:"+ tpl2ReqXml );
                    String result2 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl2ReqXml,_INFURL);
                    logger.info("****出参:"+result2);

                    if(result2==null ||"".equals(result2))
                    {
                        // errList.add(info);
                        logger.info("****接口：SaveGjgZhzd，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：SaveGjgZhzd上传失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json2 =  Xml2Json.xmltoJson(result2);
                    logger.info("****json2"+json2);
                    JSONObject envelopeObj2 = (JSONObject) json2.get("Envelope");
                    JSONObject bodyObj2 = (JSONObject) envelopeObj2.get("Body");
                    JSONObject saveGjgZhsfResponseObj2 = (JSONObject) bodyObj2.get("SaveGjgZhsfResponse");
                    JSONObject saveGjgZhsfResult2 =JSONObject.parseObject (String.valueOf( saveGjgZhsfResponseObj2.get("SaveGjgZhsfResult")));

                    String resultCode2 = saveGjgZhsfResult2.getString("SUCCESS");
                    String msg2 = saveGjgZhsfResult2.getString("MESSAGE");
                    if(!"1".equals(resultCode2))
                    {
                        logger.info("****接口：SaveGjgZhsf上传失败，"+msg2);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg2.length()>50){
                            updateparam.put("errMsg","接口：SaveGjgZhsf上传失败"+msg2.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：SaveGjgZhsf传失败"+msg2);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }

                    //更新 上传状态
                    HashMap updateparam  = new HashMap();
                    updateparam.put("peId",peId);
                    updateparam.put("visitid",visitid);
                    updateparam.put("idNo",idNo);
                    updateparam.put("sendOrderId",sendOrderId);
                    updateparam.put("tableName",tableName);
                    updateparam.put("uploadStatus","1");
                    updateparam.put("errMsg","succ");
                    updateUploadStatus(updateparam);

                }
            }catch (Exception e){
                //errList.add(info);
                e.printStackTrace();
            }
        }
        return resultMsg;
    }

    /**
     *
     * @param sendOrderId
     * @param tableName RXABS
     * @return
     */
    @RequestMapping("/saveRxgBsxx")
    @ResponseBody
    public String saveRxgBsxx(@RequestParam(value = "sendOrderId", required = true) String sendOrderId,
                              @RequestParam(value = "tableName", required = true) String tableName
    ) {
        logger.info("******保存乳腺癌病史信息******开始调用【saveRxgBsxx】");
        logger.info("****入参 批次:"+sendOrderId +",表名："+tableName);

        String resultMsg ="1";
        HashMap qryparam  = new HashMap();
        qryparam.put("sendOrderId",sendOrderId);
        qryparam.put("tableName",tableName);
        List<HashMap> uploadList = healthPatInfoService.queryUploadRxgBsxx(qryparam);
        for (HashMap info:uploadList)
        {
            try {
                if (info != null) {
                    String peId = String.valueOf(info.get("PE_ID") == null ? "" : info.get("PE_ID"));
                    String visitid = String.valueOf(info.get("PE_VISIT_ID") == null ? "0" : info.get("PE_VISIT_ID"));
                    String idNo = String.valueOf(info.get("ID_NO") == null ? "" : info.get("ID_NO"));
                    logger.info("****身份证号：" + idNo);
                    if ("".equals(idNo)) {
                        logger.info("****身份证号为空不能上传");
                        //更新 上传状态
                        HashMap updateparam = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo", idNo);
                        updateparam.put("sendOrderId", sendOrderId);
                        updateparam.put("tableName", tableName);
                        updateparam.put("uploadStatus", "0");
                        updateparam.put("errMsg", "身份证号为空不能上传");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    String result1 = this.populationIndex(idNo);
                    if(result1==null ||"".equals(result1))
                    {
                        //errList.add(info);
                        logger.info("****接口：populationIndex查询失败，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：populationIndex查询失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json1 =  Xml2Json.xmltoJson(result1);
                    JSONObject envelopeObj = (JSONObject) json1.get("Envelope");
                    JSONObject bodyObj = (JSONObject) envelopeObj.get("Body");
                    JSONObject populationIndexResponseObj = (JSONObject) bodyObj.get("PopulationIndexResponse");
                    String xmlResult1 = String.valueOf( populationIndexResponseObj.get("PopulationIndexResult"));
                    if(xmlResult1==null || "".equals(xmlResult1))
                    {
                        logger.info("****接口：populationIndex查询失败，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：populationIndex查询失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    else
                    {
                        if("0".equals(xmlResult1))
                        {
                            logger.info("****接口：populationIndex查询失败，返回为空！");
                            //更新 上传状态
                            HashMap updateparam  = new HashMap();
                            updateparam.put("peId",peId);
                            updateparam.put("visitid",visitid);
                            updateparam.put("idNo",idNo);
                            updateparam.put("sendOrderId",sendOrderId);
                            updateparam.put("tableName",tableName);
                            updateparam.put("uploadStatus","0");
                            updateparam.put("errMsg","接口：populationIndex查询失败，返回为空");
                            updateUploadStatus(updateparam);
                            continue;
                        }
                        JSONObject jsonXmlResult1 =  Xml2Json.xmltoJson(xmlResult1);
                        //{"response":{"index":{"person":{"dead_tag":"0","charge_type":"","nation":"壮族","date_of_birth":"1983/7/11","out_poverty_status":"","lastunit":"广西壮族自治区人民医院","next_of_kin":"","tprq":"","zip_code":"","next_of_kin_zip_code":"","phone_number_home":"13471195860","id_no":"452128198307116045","attached_address":"建政东路39号2栋401","identity":"","mailing_address4":"广西壮族自治区南宁市青秀区新竹街道办事处建政社区居委会","unit_in_contract":"11","relationship":"","mailing_address1":"广西壮族自治区南宁市青秀区","mailing_address2":"广西壮族自治区南宁市青秀区津头街道办事处滨湖社区居委会","mailing_address3":"广西壮族自治区南宁市青秀区","birth_place2":"广西壮族自治区南宁市青秀区津头街道办事处滨湖社区居委会","sex":"女","birth_place1":"广西壮族自治区南宁市青秀区","citizenship":"中国","next_of_kin_addr":"","next_of_kin_phone":"","attached_hujiaddress":"","phone_number_business":"","marital_status":"初婚","lasttime":"2016/8/17","lastuser":"张桂红","patient_id":"073826501","name":"农建萍","health_card_id":"","ispoor":"0","health_record_code":""}}}}
                        JSONObject responseObj = (JSONObject) jsonXmlResult1.get("response");
                        JSONObject indexObj = (JSONObject) responseObj.get("index");

                        JSONObject personObj = new JSONObject();
                        //返回可能有两条数据
                        if (indexObj.getString("person").startsWith("["))
                        {
                            //属性值是json数组
//                            JSONArray jsonArray = JSONArray.fromObject(paramObj.get("attr"));
                            JSONArray personObjarry = (JSONArray) indexObj.get("person");
                             personObj = (JSONObject) personObjarry.get(0);
                        }
                        else if (indexObj.getString("person").startsWith("{")) {
                            //属性值是json对象
                             personObj = (JSONObject) indexObj.get("person");
                        }

//                        JSONObject personObj = (JSONObject) indexObj.get("person");

                        if(personObj.isEmpty())
                        {
                            logger.info("****接口：populationIndex查询失败，返回为空！");
                            //更新 上传状态
                            HashMap updateparam  = new HashMap();
                            updateparam.put("peId",peId);
                            updateparam.put("visitid",visitid);
                            updateparam.put("idNo",idNo);
                            updateparam.put("sendOrderId",sendOrderId);
                            updateparam.put("tableName",tableName);
                            updateparam.put("uploadStatus","0");
                            updateparam.put("errMsg","查询接口：populationIndex,返回patient_id为空");
                            updateUploadStatus(updateparam);
                            continue;
                        }
                        String patient_id = (String) personObj.get("patient_id"); //主索引ID
                        if(patient_id==null || "".equals(patient_id))
                        {
                            logger.info("****接口：populationIndex查询失败，返回为空！");
                            //更新 上传状态
                            HashMap updateparam  = new HashMap();
                            updateparam.put("peId",peId);
                            updateparam.put("visitid",visitid);
                            updateparam.put("idNo",idNo);
                            updateparam.put("sendOrderId",sendOrderId);
                            updateparam.put("tableName",tableName);
                            updateparam.put("uploadStatus","0");
                            updateparam.put("errMsg","查询接口：populationIndex,返回patient_id为空");
                            updateUploadStatus(updateparam);
                            continue;
                        }

                        //保存乳腺癌病史情况 saveRxgBsxx
                        HashMap params2 = new HashMap();

                        params2.put("peId",peId);
                        params2.put("visitid",visitid);

                        //上传的体检号=体检号+体检次数
                        String getPeId = peId + visitid;
                        params2.put("getPeId",getPeId);

                        params2.put("personIndex",patient_id);

                        String dxlx = String.valueOf(info.get("DXLX") == null ? "" : info.get("DXLX"));
                        params2.put("dxlx",dxlx);

                        String czknfn = String.valueOf(info.get("CZKNFN") == null ? "" : info.get("CZKNFN"));
                        params2.put("czknfn",czknfn);

                        String education = String.valueOf(info.get("EDUCATION") == null ? "" : info.get("EDUCATION"));
                        params2.put("education",education);

                        Calendar calendar = Calendar.getInstance();
                        int year = calendar.get(Calendar.YEAR);
                        int curmonth = calendar.get(Calendar.MONTH)+1;
                        int quarterly =1;
                        if(curmonth>=1 && curmonth <=3)
                        {
                            quarterly =1;
                        }
                        else if(curmonth>=4 && curmonth <=6)
                        {
                            quarterly =2;
                        }
                        else if(curmonth>=7 && curmonth <=9)
                        {
                            quarterly =3;
                        }
                        else if(curmonth>=10 && curmonth <=12)
                        {
                            quarterly =4;
                        }
                        else{}

                        String yearReported = String.valueOf(info.get("YEAR_REPORTED") == null ? ""+year : info.get("YEAR_REPORTED"));
                        params2.put("yearReported",yearReported);

                        String quarterlyReported = String.valueOf(info.get("QUARTERLY_REPORTED") == null ? ""+quarterly : info.get("QUARTERLY_REPORTED"));
                        params2.put("quarterlyReported",quarterlyReported);

                        String lastMenstrualPeriodStr = String.valueOf(info.get("LAST_MENSTRUAL_PERIOD") == null ? "" : info.get("LAST_MENSTRUAL_PERIOD"));
                        String lastMenstrualPeriod ="";
                        if(!("".equals(lastMenstrualPeriodStr)))
                        {
                            lastMenstrualPeriod = lastMenstrualPeriodStr.substring(0,10);
                        }
                        params2.put("lastMenstrualPeriod",lastMenstrualPeriod);

                        String checkBreastCancer = String.valueOf(info.get("CHECK_BREAST_CANCER") == null ? "" : info.get("CHECK_BREAST_CANCER"));
                        params2.put("checkBreastCancer",checkBreastCancer);

                        String examinationScope = String.valueOf(info.get("EXAMINATION_SCOPE") == null ? "" : info.get("EXAMINATION_SCOPE"));
                        params2.put("examinationScope",examinationScope);

                        String bh = String.valueOf(info.get("BH") == null ? "" : info.get("BH"));
                        params2.put("bh",bh);

                        String tpl2 = ReadTpltoStr.readTol("tpl_SaveRxgBsxx.xml");
                        String tpl2ReqXml = fillParamsToTpl(tpl2,params2 );
                        logger.info("****入参:"+ tpl2ReqXml );
                        String result2 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl2ReqXml,_INFURL);
                        logger.info("****出参:"+result2);

                        if(result2==null ||"".equals(result2))
                        {
                            // errList.add(info);
                            logger.info("****接口：SaveRxgBsxx上传失败，返回为空！");
                            //更新 上传状态
                            HashMap updateparam  = new HashMap();
                            updateparam.put("peId",peId);
                            updateparam.put("visitid",visitid);
                            updateparam.put("idNo",idNo);
                            updateparam.put("sendOrderId",sendOrderId);
                            updateparam.put("tableName",tableName);
                            updateparam.put("uploadStatus","0");
                            updateparam.put("errMsg","接口：SaveRxgBsxx上传失败，返回为空");
                            updateUploadStatus(updateparam);
                            continue;
                        }
                        JSONObject json2 =  Xml2Json.xmltoJson(result2);
                        logger.info("****json2"+json2);
                        //{"Envelope":{"Body":{"SaveGjgHpvResponse":{"SaveGjgHpvResult":"{\"SUCCESS\":\"0\",\"MESSAGE\":\"0,父节点不能为空\",\"DATA\":[]}"}}}}
                        JSONObject envelopeObj2 = (JSONObject) json2.get("Envelope");
                        JSONObject bodyObj2 = (JSONObject) envelopeObj2.get("Body");
                        JSONObject saveRxgBsxxResponseObj2 = (JSONObject) bodyObj2.get("SaveRxgBsxxResponse");
                        JSONObject saveRxgBsxxResult2 =JSONObject.parseObject (String.valueOf( saveRxgBsxxResponseObj2.get("SaveRxgBsxxResult")));

                        String resultCode2 = saveRxgBsxxResult2.getString("SUCCESS");
                        String msg2 = saveRxgBsxxResult2.getString("MESSAGE");
                        if(!"1".equals(resultCode2))
                        {
                            logger.info("****接口：SaveRxgBsxx上传失败，"+msg2);
                            //更新 上传状态
                            HashMap updateparam  = new HashMap();
                            updateparam.put("peId",peId);
                            updateparam.put("visitid",visitid);
                            updateparam.put("idNo",idNo);
                            updateparam.put("sendOrderId",sendOrderId);
                            updateparam.put("tableName",tableName);
                            updateparam.put("uploadStatus","0");
                            if(msg2.length()>50){
                                updateparam.put("errMsg","接口：SaveRxgBsxx上传失败"+msg2.substring(0,50));
                            }
                            else
                            {
                                updateparam.put("errMsg","接口：SaveRxgBsxx上传失败"+msg2);
                            }

                            updateUploadStatus(updateparam);
                            continue;
                        }

                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","1");
                        updateparam.put("errMsg","succ");
                        updateUploadStatus(updateparam);
                        this.saveRxgCzxx(sendOrderId,"RXGCZXX",peId,visitid,idNo);
                        this.saveCscsjcxx(sendOrderId,"CSCSJCXX",peId,visitid,idNo);
                    }
                }


            }catch (Exception e){
                e.printStackTrace();
            }
        }

        return resultMsg;
    }


    /**
     *乳腺癌触诊情况
     */
    @ResponseBody
    public void saveRxgCzxx( String sendOrderId, String tableName, String peId, String visitid, String idNo
    ) {

        logger.info("*****乳腺癌触诊情况******开始调用【saveRxgCzxx】");
        logger.info("****入参 批次:"+sendOrderId +",表名："+tableName);

        HashMap qryparam  = new HashMap();
        qryparam.put("sendOrderId",sendOrderId);
        qryparam.put("tableName",tableName);
        qryparam.put("peId",peId);
        qryparam.put("visitid",visitid);
        qryparam.put("idNo",idNo);
        List<HashMap> uploadList = healthPatInfoService.queryUploadRxgCzxx(qryparam);
        // List<HashMap> errList = new ArrayList<HashMap>();
        for (HashMap info:uploadList)
        {
            try {
                if (info != null) {
                    //  先用主索引接口 获取主索引 再上传病史生成 档案  再查询档案 上传对应检查后，QeuryRXGIDByIdNo 才会有记录
                    //查询 QeuryRXGIDByIdNo 接口，获取 pId与 personIndex
                    logger.info("****身份证号："+idNo);
                    HashMap params1 = new HashMap();
                    params1.put("IdNo",idNo);
                    String tpl1 = ReadTpltoStr.readTol("tpl_QeuryRXGIDByIdNo.xml");
                    String tpl1ReqXml = fillParamsToTpl(tpl1,params1 );
                    logger.info("****入参:"+ tpl1ReqXml );
                    String result1 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl1ReqXml,_INFURL);
                    logger.info("****出参:"+result1);

                    if(result1==null ||"".equals(result1))
                    {
                        //errList.add(info);
                        logger.info("****接口：QeuryRXGIDByIdNo查询失败，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryRXGIDByIdNo查询失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json1 =  Xml2Json.xmltoJson(result1);
                    JSONObject envelopeObj = (JSONObject) json1.get("Envelope");
                    JSONObject bodyObj = (JSONObject) envelopeObj.get("Body");
                    JSONObject qeuryRXGIDByIdNoResponseObj = (JSONObject) bodyObj.get("QeuryRXGIDByIdNoResponse");
                    JSONObject qeuryRXGIDByIdNoResultObj =JSONObject.parseObject (String.valueOf( qeuryRXGIDByIdNoResponseObj.get("QeuryRXGIDByIdNoResult")));

                    String resultCode1 = qeuryRXGIDByIdNoResultObj.getString("SUCCESS");
                    String msg1 = qeuryRXGIDByIdNoResultObj.getString("MESSAGE");
                    if(!"1".equals(resultCode1))
                    {
                        logger.info("****接口：QeuryRXGIDByIdNo查询失败，"+msg1);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg1.length()>50){
                            updateparam.put("errMsg","接口：saveRxgCzxx上传失败"+msg1.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：saveRxgCzxx上传失败"+msg1);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONArray data1arr = qeuryRXGIDByIdNoResultObj.getJSONArray("DATA");
                    if(data1arr==null || (data1arr!=null && data1arr.size()==0))
                    {
                        logger.info("****接口：QeuryRXGIDByIdNo 返回结果中DATA为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryRXGIDByIdNo 返回结果中DATA为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
//{"SUCCESS":"1","MESSAGE":"","DATA":[{"PE_ID":"6407a78c-0c09-4fa9-926f-5aa2f04fa946","PERSON_INDEX":"073826501","ID_NO":"452128198307116045","YEAR_REPORTED":"2022","QUARTERLY_REPORTED":"3","BH":""}]}
                    JSONObject data1Index0 = (JSONObject) data1arr.get(0);
                    String pId = String.valueOf(data1Index0.get("PE_ID") == null ? "" : data1Index0.get("PE_ID"));
                    String personIndex = String.valueOf(data1Index0.get("PERSON_INDEX") == null ? "" : data1Index0.get("PERSON_INDEX"));
                    logger.info("****接口：QeuryRXGIDByIdNo 返回结果中PId："+pId +",personIndex:"+personIndex);
                    if("".equals(pId))
                    {
                        logger.info("****接口：QeuryRXGIDByIdNo 返回结果中DATA中：PE_ID为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryRXGIDByIdNo 返回结果中DATA中：PE_ID为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    if("".equals(personIndex))
                    {
                        logger.info("****接口：QeuryRXGIDByIdNo 返回结果中DATA中：person_index为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryRXGIDByIdNo 返回结果中DATA中：person_index为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    //上报
                    HashMap params2 = new HashMap();

                    params2.put("peId",peId);
                    params2.put("visitid",visitid);

                    //上传的体检号=体检号+体检次数
                    String getPeId = peId + visitid;
                    params2.put("getPeId",getPeId);

                    params2.put("personIndex",personIndex);
                    params2.put("pId",pId);

                    //测试数据
                    // params2.put("personIndex","9999");
                    // params2.put("pId","TJ01937443");

                    String clinicalExaminationResult = String.valueOf(info.get("CLINICAL_EXAMINATION_RESULT") == null ? "" : info.get("CLINICAL_EXAMINATION_RESULT"));
                    params2.put("clinicalExaminationResult",clinicalExaminationResult);

                    String pleaseSpecify = String.valueOf(info.get("PLEASE_SPECIFY") == null ? "" : info.get("PLEASE_SPECIFY"));
                    params2.put("pleaseSpecify",pleaseSpecify);

                    String clinicalExaminationResult2 = String.valueOf(info.get("CLINICAL_EXAMINATION_RESULT2") == null ? "" : info.get("CLINICAL_EXAMINATION_RESULT2"));
                    params2.put("clinicalExaminationResult2",clinicalExaminationResult2);

                    String pleaseSpecify2 = String.valueOf(info.get("PLEASE_SPECIFY2") == null ? "" : info.get("PLEASE_SPECIFY2"));
                    params2.put("pleaseSpecify2",pleaseSpecify2);

                    String checkUnitcode1 = String.valueOf(info.get("CHECK_UNITCODE1") == null ? "4501030014" : info.get("CHECK_UNITCODE1"));
                    params2.put("checkUnitcode1",checkUnitcode1);

                    String checkUnitname1 = String.valueOf(info.get("CHECK_UNITNAME1") == null ? "广西壮族自治区人民医院" : info.get("CHECK_UNITNAME1"));
                    params2.put("checkUnitname1",checkUnitname1);

                    String inoutSign1 = String.valueOf(info.get("INOUT_SIGN1") == null ? "0" : info.get("INOUT_SIGN1"));
                    params2.put("inoutSign1",inoutSign1);

                    String checkPerson = String.valueOf(info.get("CHECK_PERSON") == null ? "" : info.get("CHECK_PERSON"));
                    params2.put("checkPerson",checkPerson);

                    String tpl2 = ReadTpltoStr.readTol("tpl_SaveRxgCzxx.xml");
                    String tpl2ReqXml = fillParamsToTpl(tpl2,params2 );
                    logger.info("****入参:"+ tpl2ReqXml );
                    String result2 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl2ReqXml,_INFURL);
                    logger.info("****出参:"+result2);

                    if(result2==null ||"".equals(result2))
                    {
                        // errList.add(info);
                        logger.info("****接口：SaveRxgCzxx，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：SaveRxgCzxx上传失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json2 =  Xml2Json.xmltoJson(result2);
                    logger.info("****json2"+json2);
                    JSONObject envelopeObj2 = (JSONObject) json2.get("Envelope");
                    JSONObject bodyObj2 = (JSONObject) envelopeObj2.get("Body");
                    JSONObject saveRxgCzxxResponseObj2 = (JSONObject) bodyObj2.get("SaveRxgCzxxResponse");
                    JSONObject saveRxgCzxxResult2 =JSONObject.parseObject (String.valueOf( saveRxgCzxxResponseObj2.get("SaveRxgCzxxResult")));

                    String resultCode2 = saveRxgCzxxResult2.getString("SUCCESS");
                    String msg2 = saveRxgCzxxResult2.getString("MESSAGE");
                    if(!"1".equals(resultCode2))
                    {
                        logger.info("****接口：SaveRxgCzxx上传失败，"+msg2);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg2.length()>50){
                            updateparam.put("errMsg","接口：SaveRxgCzxx上传失败"+msg2.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：SaveRxgCzxx上传失败"+msg2);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }

                    //更新 上传状态
                    HashMap updateparam  = new HashMap();
                    updateparam.put("peId",peId);
                    updateparam.put("visitid",visitid);
                    updateparam.put("idNo",idNo);
                    updateparam.put("sendOrderId",sendOrderId);
                    updateparam.put("tableName",tableName);
                    updateparam.put("uploadStatus","1");
                    updateparam.put("errMsg","succ");
                    updateUploadStatus(updateparam);

                }
            }catch (Exception e){
                //errList.add(info);
                e.printStackTrace();
            }
        }
    }


    /**
     *乳腺癌彩超
     */
    @RequestMapping("/saveRxgBc")
    @ResponseBody
    public void saveCscsjcxx( @RequestParam(value = "sendOrderId", required = true) String sendOrderId,
                              @RequestParam(value = "tableName", required = true) String tableName, String peId, String visitid, String idNo
    )
    {

        logger.info("*****乳腺癌彩超******开始调用【saveCscsjcxx】");
        logger.info("****入参 批次:"+sendOrderId +",表名："+tableName );

        HashMap qryparam  = new HashMap();
        qryparam.put("sendOrderId",sendOrderId);
        qryparam.put("tableName",tableName);
//        if(!ObjectUtils.isEmpty(peId))        {qryparam.put("peId",peId);}
//        if(!ObjectUtils.isEmpty(peId))        {qryparam.put("visitid",visitid);}
//        if(!ObjectUtils.isEmpty(peId))        {qryparam.put("idNo",idNo);}
        qryparam.put("peId",peId);
        qryparam.put("visitid",visitid);
        qryparam.put("idNo",idNo);
        List<HashMap> uploadList = healthPatInfoService.queryUploadCscsjcxx(qryparam);
//        qryparam.put("idNo",idNo);
        // List<HashMap> errList = new ArrayList<HashMap>();
        for (HashMap info:uploadList)
        {
            try {
                if (info != null) {
                    //  先用主索引接口 获取主索引 再上传病史生成 档案  再查询档案 上传对应检查后，QeuryRXGIDByIdNo 才会有记录
                    //查询 QeuryRXGIDByIdNo 接口，获取 pId与 personIndex
                    logger.info("****身份证号："+idNo);
                    HashMap params1 = new HashMap();
//                    String ID_NO = String.valueOf(info.get("ID_NO") == null ? "" : info.get("ID_NO"));
                    params1.put("IdNo",idNo);
                    String tpl1 = ReadTpltoStr.readTol("tpl_QeuryRXGIDByIdNo.xml");
                    String tpl1ReqXml = fillParamsToTpl(tpl1,params1 );
                    logger.info("****入参:"+ tpl1ReqXml );
                    String result1 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl1ReqXml,_INFURL);
                    logger.info("****出参:"+result1);

                    if(result1==null ||"".equals(result1))
                    {
                        //errList.add(info);
                        logger.info("****接口：QeuryRXGIDByIdNo查询失败，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryRXGIDByIdNo查询失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json1 =  Xml2Json.xmltoJson(result1);
                    JSONObject envelopeObj = (JSONObject) json1.get("Envelope");
                    JSONObject bodyObj = (JSONObject) envelopeObj.get("Body");
                    JSONObject qeuryRXGIDByIdNoResponseObj = (JSONObject) bodyObj.get("QeuryRXGIDByIdNoResponse");
                    JSONObject qeuryRXGIDByIdNoResultObj =JSONObject.parseObject (String.valueOf( qeuryRXGIDByIdNoResponseObj.get("QeuryRXGIDByIdNoResult")));

                    String resultCode1 = qeuryRXGIDByIdNoResultObj.getString("SUCCESS");
                    String msg1 = qeuryRXGIDByIdNoResultObj.getString("MESSAGE");
                    if(!"1".equals(resultCode1))
                    {
                        logger.info("****接口：QeuryRXGIDByIdNo查询失败，"+msg1);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg1.length()>50){
                            updateparam.put("errMsg","接口：saveCscsjcxx上传失败"+msg1.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：saveCscsjcxx上传失败"+msg1);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONArray data1arr = qeuryRXGIDByIdNoResultObj.getJSONArray("DATA");
                    if(data1arr==null || (data1arr!=null && data1arr.size()==0))
                    {
                        logger.info("****接口：QeuryRXGIDByIdNo 返回结果中DATA为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryRXGIDByIdNo 返回结果中DATA为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
//{"SUCCESS":"1","MESSAGE":"","DATA":[{"PE_ID":"6407a78c-0c09-4fa9-926f-5aa2f04fa946","PERSON_INDEX":"073826501","ID_NO":"452128198307116045","YEAR_REPORTED":"2022","QUARTERLY_REPORTED":"3","BH":""}]}
//                    JSONObject data1Index0 = (JSONObject) data1arr.get(0);
//                    String pId = String.valueOf(data1Index0.get("PE_ID") == null ? "" : data1Index0.get("PE_ID"));
//                    String personIndex = String.valueOf(data1Index0.get("PERSON_INDEX") == null ? "" : data1Index0.get("PERSON_INDEX"));
                    String pId="";
                    String personIndex="";
                    //返回的数据有多条，要找到对应体检号这条
                    for (int i = 0; i < data1arr.size(); i++) {
                        JSONObject jsonObject = data1arr.getJSONObject(i);
                        String PE_ID = jsonObject.getString("PE_ID");
                        if (PE_ID.equals(peId+visitid)) {
                            pId = String.valueOf(jsonObject.get("PE_ID") == null ? "" : jsonObject.get("PE_ID"));
                            personIndex = String.valueOf(jsonObject.get("PERSON_INDEX") == null ? "" : jsonObject.get("PERSON_INDEX"));
                        }
                    }
                    logger.info("****接口：QeuryRXGIDByIdNo 返回结果中PId："+pId +",personIndex:"+personIndex);
                    if("".equals(pId))
                    {
                        logger.info("****接口：QeuryRXGIDByIdNo 返回结果中DATA中：PE_ID为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryRXGIDByIdNo 返回结果中DATA中：PE_ID为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    if("".equals(personIndex))
                    {
                        logger.info("****接口：QeuryRXGIDByIdNo 返回结果中DATA中：person_index为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryRXGIDByIdNo 返回结果中DATA中：person_index为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    //上报
                    HashMap params2 = new HashMap();

                    params2.put("peId",peId);
                    params2.put("visitid",visitid);

                    //上传的体检号=体检号+体检次数
                    String getPeId = peId + visitid;
                    params2.put("getPeId",getPeId);

                    params2.put("personIndex",personIndex);
                    params2.put("pId",pId);

                    //测试数据
                    // params2.put("personIndex","9999");
                    // params2.put("pId","TJ01937443");

                    String size1 = String.valueOf(info.get("SIZE1") == null ? "" : info.get("SIZE1"));
                    params2.put("size1",size1);

                    String size2 = String.valueOf(info.get("SIZE2") == null ? "" : info.get("SIZE2"));
                    params2.put("size2",size2);

                    String size3 = String.valueOf(info.get("SIZE3") == null ? "" : info.get("SIZE3"));
                    params2.put("size3",size3);

                    String ysize1 = String.valueOf(info.get("YSIZE1") == null ? "" : info.get("YSIZE1"));
                    params2.put("ysize1",ysize1);

                    String ysize2 = String.valueOf(info.get("YSIZE2") == null ? "" : info.get("YSIZE2"));
                    params2.put("ysize2",ysize2);

                    String ysize3 = String.valueOf(info.get("YSIZE3") == null ? "" : info.get("YSIZE3"));
                    params2.put("ysize3",ysize3);

                    String cyst = String.valueOf(info.get("CYST") == null ? "" : info.get("CYST"));
                    params2.put("cyst",cyst);

                    String solidMass = String.valueOf(info.get("SOLID_MASS") == null ? "" : info.get("SOLID_MASS"));
                    params2.put("solidMass",solidMass);

                    String form = String.valueOf(info.get("FORM") == null ? "" : info.get("FORM"));
                    params2.put("form",form);

                    String direction = String.valueOf(info.get("DIRECTION") == null ? "" : info.get("DIRECTION"));
                    params2.put("direction",direction);

                    String boundary = String.valueOf(info.get("BOUNDARY") == null ? "" : info.get("BOUNDARY"));
                    params2.put("boundary",boundary);

                    String edge = String.valueOf(info.get("EDGE") == null ? "" : info.get("EDGE"));
                    params2.put("edge",edge);

                    String internalEcho = String.valueOf(info.get("INTERNAL_ECHO") == null ? "" : info.get("INTERNAL_ECHO"));
                    params2.put("internalEcho",internalEcho);

                    String posteriorEcho = String.valueOf(info.get("POSTERIOR_ECHO") == null ? "" : info.get("POSTERIOR_ECHO"));
                    params2.put("posteriorEcho",posteriorEcho);

                    String calcification = String.valueOf(info.get("CALCIFICATION") == null ? "" : info.get("CALCIFICATION"));
                    params2.put("calcification",calcification);

                    String bloodFlow = String.valueOf(info.get("BLOOD_FLOW") == null ? "" : info.get("BLOOD_FLOW"));
                    params2.put("bloodFlow",bloodFlow);

                    String others = String.valueOf(info.get("OTHERS") == null ? "" : info.get("OTHERS"));
                    params2.put("others",others);

                    String ycyst = String.valueOf(info.get("YCYST") == null ? "" : info.get("YCYST"));
                    params2.put("ycyst",ycyst);

                    String ysolidMass = String.valueOf(info.get("YSOLID_MASS") == null ? "" : info.get("YSOLID_MASS"));
                    params2.put("ysolidMass",ysolidMass);

                    String yform = String.valueOf(info.get("YFORM") == null ? "" : info.get("YFORM"));
                    params2.put("yform",yform);

                    String ydirection = String.valueOf(info.get("YDIRECTION") == null ? "" : info.get("YDIRECTION"));
                    params2.put("ydirection",ydirection);

                    String yboundary = String.valueOf(info.get("YBOUNDARY") == null ? "" : info.get("YBOUNDARY"));
                    params2.put("yboundary",yboundary);

                    String yedge = String.valueOf(info.get("YEDGE") == null ? "" : info.get("YEDGE"));
                    params2.put("yedge",yedge);

                    String yinternalEcho = String.valueOf(info.get("YINTERNAL_ECHO") == null ? "" : info.get("YINTERNAL_ECHO"));
                    params2.put("yinternalEcho",yinternalEcho);

                    String yposteriorEcho = String.valueOf(info.get("YPOSTERIOR_ECHO") == null ? "" : info.get("YPOSTERIOR_ECHO"));
                    params2.put("yposteriorEcho",yposteriorEcho);

                    String ycalcification = String.valueOf(info.get("YCALCIFICATION") == null ? "" : info.get("YCALCIFICATION"));
                    params2.put("ycalcification",ycalcification);

                    String ybloodFlow = String.valueOf(info.get("YBLOOD_FLOW") == null ? "" : info.get("YBLOOD_FLOW"));
                    params2.put("ybloodFlow",ybloodFlow);

                    String yothers = String.valueOf(info.get("YOTHERS") == null ? "" : info.get("YOTHERS"));
                    params2.put("yothers",yothers);

                    String suggestion = String.valueOf(info.get("SUGGESTION") == null ? "" : info.get("SUGGESTION"));
                    params2.put("suggestion",suggestion);

                    String classification = String.valueOf(info.get("CLASSIFICATION") == null ? "" : info.get("CLASSIFICATION"));
                    params2.put("classification",classification);

                    String yclassification = String.valueOf(info.get("YCLASSIFICATION") == null ? "" : info.get("YCLASSIFICATION"));
                    params2.put("yclassification",yclassification);

                    String position = String.valueOf(info.get("POSITION") == null ? "" : info.get("POSITION"));
                    params2.put("position",position);

                    String yposition = String.valueOf(info.get("YPOSITION") == null ? "" : info.get("YPOSITION"));
                    params2.put("yposition",yposition);

                    String checkUnitcode1 = String.valueOf(info.get("CHECK_UNITCODE1") == null ? "4501030014" : info.get("CHECK_UNITCODE1"));
                    params2.put("checkUnitcode1",checkUnitcode1);

                    String checkUnitname1 = String.valueOf(info.get("CHECK_UNITNAME1") == null ? "广西壮族自治区人民医院" : info.get("CHECK_UNITNAME1"));
                    params2.put("checkUnitname1",checkUnitname1);

                    String inoutSign1 = String.valueOf(info.get("INOUT_SIGN1") == null ? "0" : info.get("INOUT_SIGN1"));
                    params2.put("inoutSign1",inoutSign1);

                    String checkPerson = String.valueOf(info.get("CHECK_PERSON") == null ? "" : info.get("CHECK_PERSON"));
                    params2.put("checkPerson",checkPerson);

                    String reportDatestr = String.valueOf(info.get("CHECK_DATE") == null ? "" : info.get("CHECK_DATE"));
                    String checkDate ="";
                    if(!("".equals(reportDatestr)))
                    {
                        checkDate = reportDatestr.substring(0,10);
                    }
                    params2.put("checkDate",checkDate);

                    String tpl2 = ReadTpltoStr.readTol("tpl_SaveCscsjcxx.xml");

                    String tpl2ReqXml = fillParamsToTpl(tpl2,params2 );
                    logger.info("****入参:"+ tpl2ReqXml );
                    String result2 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl2ReqXml,_INFURL);
                    logger.info("****出参:"+result2);

                    if(result2==null ||"".equals(result2))
                    {
                        // errList.add(info);
                        logger.info("****接口：SaveCscsjcxx，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：SaveCscsjcxx上传失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json2 =  Xml2Json.xmltoJson(result2);
                    logger.info("****json2"+json2);
                    JSONObject envelopeObj2 = (JSONObject) json2.get("Envelope");
                    JSONObject bodyObj2 = (JSONObject) envelopeObj2.get("Body");
                    JSONObject saveCscsjcxxResponseObj2 = (JSONObject) bodyObj2.get("SaveCscsjcxxResponse");
                    JSONObject saveCscsjcxxResult2 =JSONObject.parseObject (String.valueOf( saveCscsjcxxResponseObj2.get("SaveCscsjcxxResult")));

                    String resultCode2 = saveCscsjcxxResult2.getString("SUCCESS");
                    String msg2 = saveCscsjcxxResult2.getString("MESSAGE");
                    if(!"1".equals(resultCode2))
                    {
                        logger.info("****接口：SaveCscsjcxx上传失败，"+msg2);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg2.length()>50){
                            updateparam.put("errMsg","接口：SaveCscsjcxx上传失败"+msg2.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：SaveCscsjcxx上传失败"+msg2);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }

                    //更新 上传状态
                    HashMap updateparam  = new HashMap();
                    updateparam.put("peId",peId);
                    updateparam.put("visitid",visitid);
                    updateparam.put("idNo",idNo);
                    updateparam.put("sendOrderId",sendOrderId);
                    updateparam.put("tableName",tableName);
                    updateparam.put("uploadStatus","1");
                    updateparam.put("errMsg","succ");
                    updateUploadStatus(updateparam);

                }
            }catch (Exception e){
                //errList.add(info);
                e.printStackTrace();
            }
        }
    }


    /**
     *乳腺癌 x 线检查
     * @param sendOrderId
     * @param tableName RXAXX
     * @return
     */
    @RequestMapping("/saveRxxxxx")
    @ResponseBody
    public String saveRxxxxx(@RequestParam(value = "sendOrderId", required = true) String sendOrderId,
                               @RequestParam(value = "tableName", required = true) String tableName
    )
    {
        logger.info("*****乳腺癌 x 线检查******开始调用【saveRxxxxx】");
        logger.info("****入参 批次:"+sendOrderId +",表名："+tableName);

        String resultMsg ="1";
        HashMap qryparam  = new HashMap();
        qryparam.put("sendOrderId",sendOrderId);
        qryparam.put("tableName",tableName);
        List<HashMap> uploadList = healthPatInfoService.queryUploadRxaXx(qryparam);
        // List<HashMap> errList = new ArrayList<HashMap>();
        for (HashMap info:uploadList)
        {
            try {
                if (info != null) {
                    //  先用主索引接口 获取主索引 再上传病史生成 档案  再查询档案 上传对应检查后，QeuryRXGIDByIdNo 才会有记录
                    //查询 QeuryRXGIDByIdNo 接口，获取 pId与 personIndex
                    String peId = String.valueOf(info.get("PE_ID") == null ? "" : info.get("PE_ID"));
                    String visitid = String.valueOf(info.get("PE_VISIT_ID") == null ? "0" : info.get("PE_VISIT_ID"));
                    String idNo = String.valueOf(info.get("ID_NO") == null ? "" : info.get("ID_NO"));
                    logger.info("****身份证号："+idNo);
                    if ("".equals(idNo)) {
                        logger.info("****身份证号为空不能上传");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","身份证号为空不能上传");
                        updateUploadStatus(updateparam);
                        continue;
                    }

                    HashMap params1 = new HashMap();
                    params1.put("IdNo",idNo);
                    String tpl1 = ReadTpltoStr.readTol("tpl_QeuryRXGIDByIdNo.xml");
                    String tpl1ReqXml = fillParamsToTpl(tpl1,params1 );
                    logger.info("****入参:"+ tpl1ReqXml );
                    String result1 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl1ReqXml,_INFURL);
                    logger.info("****出参:"+result1);

                    if(result1==null ||"".equals(result1))
                    {
                        //errList.add(info);
                        logger.info("****接口：QeuryRXGIDByIdNo查询失败，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryRXGIDByIdNo查询失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json1 =  Xml2Json.xmltoJson(result1);
                    JSONObject envelopeObj = (JSONObject) json1.get("Envelope");
                    JSONObject bodyObj = (JSONObject) envelopeObj.get("Body");
                    JSONObject qeuryRXGIDByIdNoResponseObj = (JSONObject) bodyObj.get("QeuryRXGIDByIdNoResponse");
                    JSONObject qeuryRXGIDByIdNoResultObj =JSONObject.parseObject (String.valueOf( qeuryRXGIDByIdNoResponseObj.get("QeuryRXGIDByIdNoResult")));

                    String resultCode1 = qeuryRXGIDByIdNoResultObj.getString("SUCCESS");
                    String msg1 = qeuryRXGIDByIdNoResultObj.getString("MESSAGE");
                    if(!"1".equals(resultCode1))
                    {
                        logger.info("****接口：QeuryRXGIDByIdNo查询失败，"+msg1);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg1.length()>50){
                            updateparam.put("errMsg","接口：saveRxxxxx上传失败"+msg1.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：saveRxxxxx上传失败"+msg1);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONArray data1arr = qeuryRXGIDByIdNoResultObj.getJSONArray("DATA");
                    if(data1arr==null || (data1arr!=null && data1arr.size()==0))
                    {
                        logger.info("****接口：QeuryRXGIDByIdNo 返回结果中DATA为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryRXGIDByIdNo 返回结果中DATA为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
//{"SUCCESS":"1","MESSAGE":"","DATA":[{"PE_ID":"6407a78c-0c09-4fa9-926f-5aa2f04fa946","PERSON_INDEX":"073826501","ID_NO":"452128198307116045","YEAR_REPORTED":"2022","QUARTERLY_REPORTED":"3","BH":""}]}
//                    JSONObject data1Index0 = (JSONObject) data1arr.get(0);
//                    String pId = String.valueOf(data1Index0.get("PE_ID") == null ? "" : data1Index0.get("PE_ID"));
//                    String personIndex = String.valueOf(data1Index0.get("PERSON_INDEX") == null ? "" : data1Index0.get("PERSON_INDEX"));
                    String pId="";
                    String personIndex="";
                    //返回的数据有多条，要找到对应体检号这条
                    for (int i = 0; i < data1arr.size(); i++) {
                        JSONObject jsonObject = data1arr.getJSONObject(i);
                        String PE_ID = jsonObject.getString("PE_ID");
                        if (PE_ID.equals(peId+visitid)) {
                            pId = String.valueOf(jsonObject.get("PE_ID") == null ? "" : jsonObject.get("PE_ID"));
                            personIndex = String.valueOf(jsonObject.get("PERSON_INDEX") == null ? "" : jsonObject.get("PERSON_INDEX"));
                        }
                    }
                    logger.info("****接口：QeuryRXGIDByIdNo 返回结果中PId："+pId +",personIndex:"+personIndex);
                    if("".equals(pId))
                    {
                        logger.info("****接口：QeuryRXGIDByIdNo 返回结果中DATA中：PE_ID为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryRXGIDByIdNo 返回结果中DATA中：PE_ID为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    if("".equals(personIndex))
                    {
                        logger.info("****接口：QeuryRXGIDByIdNo 返回结果中DATA中：person_index为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryRXGIDByIdNo 返回结果中DATA中：person_index为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    //上报
                    HashMap params2 = new HashMap();

                    params2.put("peId",peId);
                    params2.put("visitid",visitid);

                    //上传的体检号=体检号+体检次数
                    String getPeId = peId + visitid;
                    params2.put("getPeId",getPeId);

                    params2.put("personIndex",personIndex);
                    params2.put("pId",pId);

                    //测试数据
                    // params2.put("personIndex","9999");
                    // params2.put("pId","TJ01937443");

                    String classification = String.valueOf(info.get("CLASSIFICATION") == null ? "" : info.get("CLASSIFICATION"));
                    params2.put("classification",classification);

                    String tumor = String.valueOf(info.get("TUMOR") == null ? "" : info.get("TUMOR"));
                    params2.put("tumor",tumor);

                    String size1 = String.valueOf(info.get("SIZE1") == null ? "" : info.get("SIZE1"));
                    params2.put("size1",size1);

                    String size2 = String.valueOf(info.get("SIZE2") == null ? "" : info.get("SIZE2"));
                    params2.put("size2",size2);

                    String suspectedCalcification = String.valueOf(info.get("SUSPECTED_CALCIFICATION") == null ? "" : info.get("SUSPECTED_CALCIFICATION"));
                    params2.put("suspectedCalcification",suspectedCalcification);

                    String disorganization = String.valueOf(info.get("DISORGANIZATION") == null ? "" : info.get("DISORGANIZATION"));
                    params2.put("disorganization",disorganization);

                    String onTheOutside = String.valueOf(info.get("ON_THE_OUTSIDE") == null ? "" : info.get("ON_THE_OUTSIDE"));
                    params2.put("onTheOutside",onTheOutside);

                    String underThe = String.valueOf(info.get("UNDER_THE") == null ? "" : info.get("UNDER_THE"));
                    params2.put("underThe",underThe);

                    String onTheInside = String.valueOf(info.get("ON_THE_INSIDE") == null ? "" : info.get("ON_THE_INSIDE"));
                    params2.put("onTheInside",onTheInside);

                    String inThe = String.valueOf(info.get("IN_THE") == null ? "" : info.get("IN_THE"));
                    params2.put("inThe",inThe);

                    String theCentralArea = String.valueOf(info.get("THE_CENTRAL_AREA") == null ? "" : info.get("THE_CENTRAL_AREA"));
                    params2.put("theCentralArea",theCentralArea);

                    String posteriorAreola = String.valueOf(info.get("POSTERIOR_AREOLA") == null ? "" : info.get("POSTERIOR_AREOLA"));
                    params2.put("posteriorAreola",posteriorAreola);


                    String other = String.valueOf(info.get("OTHER") == null ? "" : info.get("OTHER"));
                    params2.put("other",other);

                    String yclassification = String.valueOf(info.get("YCLASSIFICATION") == null ? "" : info.get("YCLASSIFICATION"));
                    params2.put("yclassification",yclassification);

                    String ytumor = String.valueOf(info.get("YTUMOR") == null ? "" : info.get("YTUMOR"));
                    params2.put("ytumor",ytumor);

                    String ysize1 = String.valueOf(info.get("YSIZE1") == null ? "" : info.get("YSIZE1"));
                    params2.put("ysize1",ysize1);

                    String ysize2 = String.valueOf(info.get("YSIZE2") == null ? "" : info.get("YSIZE2"));
                    params2.put("ysize2",ysize2);

                    String ysuspectedCalcification = String.valueOf(info.get("YSUSPECTED_CALCIFICATION") == null ? "" : info.get("YSUSPECTED_CALCIFICATION"));
                    params2.put("ysuspectedCalcification",ysuspectedCalcification);

                    String ydisorganization = String.valueOf(info.get("YDISORGANIZATION") == null ? "" : info.get("YDISORGANIZATION"));
                    params2.put("ydisorganization",ydisorganization);

                    String yonTheOutside = String.valueOf(info.get("YON_THE_OUTSIDE") == null ? "" : info.get("YON_THE_OUTSIDE"));
                    params2.put("yonTheOutside",yonTheOutside);

                    String yunderThe = String.valueOf(info.get("YUNDER_THE") == null ? "" : info.get("YUNDER_THE"));
                    params2.put("yunderThe",yunderThe);

                    String yonTheInside = String.valueOf(info.get("YON_THE_INSIDE") == null ? "" : info.get("YON_THE_INSIDE"));
                    params2.put("yonTheInside",yonTheInside);

                    String yinThe = String.valueOf(info.get("YIN_THE") == null ? "" : info.get("YIN_THE"));
                    params2.put("yinThe",yinThe);

                    String ytheCentralArea = String.valueOf(info.get("YTHE_CENTRAL_AREA") == null ? "" : info.get("YTHE_CENTRAL_AREA"));
                    params2.put("ytheCentralArea",ytheCentralArea);

                    String yposteriorAreola = String.valueOf(info.get("YPOSTERIOR_AREOLA") == null ? "" : info.get("YPOSTERIOR_AREOLA"));
                    params2.put("yposteriorAreola",yposteriorAreola);


                    String yother = String.valueOf(info.get("YOTHER") == null ? "" : info.get("YOTHER"));
                    params2.put("yother",yother);

                    String suggestion = String.valueOf(info.get("SUGGESTION") == null ? "" : info.get("SUGGESTION"));
                    params2.put("suggestion",suggestion);

                    String inoutSign1 = String.valueOf(info.get("INOUTSIGN1") == null ? "0" : info.get("INOUTSIGN1"));
                    params2.put("inoutSign1",inoutSign1);

                    String reportPerson = String.valueOf(info.get("CHECK_PERSON") == null ? "" : info.get("CHECK_PERSON"));
                    params2.put("reportPerson",reportPerson);

                    String reportDatestr = String.valueOf(info.get("CHECK_DATE") == null ? "" : info.get("CHECK_DATE"));
                    String reportDate ="";
                    if(!("".equals(reportDatestr)))
                    {
                        reportDate = reportDatestr.substring(0,10);
                    }
                    params2.put("reportDate",reportDate);

                    String tpl2 = ReadTpltoStr.readTol("tp_SaveRxxxxx.xml");
                    String tpl2ReqXml = fillParamsToTpl(tpl2,params2 );
                    logger.info("****入参:"+ tpl2ReqXml );
                    String result2 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl2ReqXml,_INFURL);
                    logger.info("****出参:"+result2);

                    if(result2==null ||"".equals(result2))
                    {
                        // errList.add(info);
                        logger.info("****接口：SaveRxxxxx，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：SaveRxxxxx上传失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json2 =  Xml2Json.xmltoJson(result2);
                    logger.info("****json2"+json2);
                    JSONObject envelopeObj2 = (JSONObject) json2.get("Envelope");
                    JSONObject bodyObj2 = (JSONObject) envelopeObj2.get("Body");
                    JSONObject saveRxxxxxResponseObj2 = (JSONObject) bodyObj2.get("SaveRxxxxxResponse");
                    JSONObject saveRxxxxxResult2 =JSONObject.parseObject (String.valueOf( saveRxxxxxResponseObj2.get("SaveRxxxxxResult")));

                    String resultCode2 = saveRxxxxxResult2.getString("SUCCESS");
                    String msg2 = saveRxxxxxResult2.getString("MESSAGE");
                    if(!"1".equals(resultCode2))
                    {
                        logger.info("****接口：SaveRxxxxx上传失败，"+msg2);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg2.length()>50){
                            updateparam.put("errMsg","接口：SaveRxxxxx上传失败"+msg2.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：SaveRxxxxx上传失败"+msg2);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }

                    //更新 上传状态
                    HashMap updateparam  = new HashMap();
                    updateparam.put("peId",peId);
                    updateparam.put("visitid",visitid);
                    updateparam.put("idNo",idNo);
                    updateparam.put("sendOrderId",sendOrderId);
                    updateparam.put("tableName",tableName);
                    updateparam.put("uploadStatus","1");
                    updateparam.put("errMsg","succ");
                    updateUploadStatus(updateparam);

                }
            }catch (Exception e){
                //errList.add(info);
                e.printStackTrace();
            }
        }
        return resultMsg;
    }


    /**
     * 乳腺癌最终随访
     * @param sendOrderId
     * @param tableName RXASF
     * @return
     */
    @RequestMapping("/saveZzsfxx")
    @ResponseBody
    public String saveZzsfxx(@RequestParam(value = "sendOrderId", required = true) String sendOrderId,
                             @RequestParam(value = "tableName", required = true) String tableName
    )
    {
        logger.info("*****乳腺癌最终随访******开始调用【saveZzsfxx】");
        logger.info("****入参 批次:"+sendOrderId +",表名："+tableName);

        String resultMsg ="1";
        HashMap qryparam  = new HashMap();
        qryparam.put("sendOrderId",sendOrderId);
        qryparam.put("tableName",tableName);
        List<HashMap> uploadList = healthPatInfoService.queryUploadRxaSf(qryparam);
        // List<HashMap> errList = new ArrayList<HashMap>();
        for (HashMap info:uploadList)
        {
            try {
                if (info != null) {
                    //  先用主索引接口 获取主索引 再上传病史生成 档案  再查询档案 上传对应检查后，QeuryRXGIDByIdNo 才会有记录
                    //查询 QeuryRXGIDByIdNo 接口，获取 pId与 personIndex
                    String peId = String.valueOf(info.get("PE_ID") == null ? "" : info.get("PE_ID"));
                    String visitid = String.valueOf(info.get("PE_VISIT_ID") == null ? "0" : info.get("PE_VISIT_ID"));
                    String idNo = String.valueOf(info.get("ID_NO") == null ? "" : info.get("ID_NO"));
                    logger.info("****身份证号："+idNo);
                    if ("".equals(idNo)) {
                        logger.info("****身份证号为空不能上传");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId", peId);
                        updateparam.put("visitid", visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","身份证号为空不能上传");
                        updateUploadStatus(updateparam);
                        continue;
                    }

                    HashMap params1 = new HashMap();
                    params1.put("IdNo",idNo);
                    String tpl1 = ReadTpltoStr.readTol("tpl_QeuryRXGIDByIdNo.xml");
                    String tpl1ReqXml = fillParamsToTpl(tpl1,params1 );
                    logger.info("****入参:"+ tpl1ReqXml );
                    String result1 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl1ReqXml,_INFURL);
                    logger.info("****出参:"+result1);

                    if(result1==null ||"".equals(result1))
                    {
                        //errList.add(info);
                        logger.info("****接口：QeuryRXGIDByIdNo查询失败，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryRXGIDByIdNo查询失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json1 =  Xml2Json.xmltoJson(result1);
                    JSONObject envelopeObj = (JSONObject) json1.get("Envelope");
                    JSONObject bodyObj = (JSONObject) envelopeObj.get("Body");
                    JSONObject qeuryRXGIDByIdNoResponseObj = (JSONObject) bodyObj.get("QeuryRXGIDByIdNoResponse");
                    JSONObject qeuryRXGIDByIdNoResultObj =JSONObject.parseObject (String.valueOf( qeuryRXGIDByIdNoResponseObj.get("QeuryRXGIDByIdNoResult")));

                    String resultCode1 = qeuryRXGIDByIdNoResultObj.getString("SUCCESS");
                    String msg1 = qeuryRXGIDByIdNoResultObj.getString("MESSAGE");
                    if(!"1".equals(resultCode1))
                    {
                        logger.info("****接口：QeuryRXGIDByIdNo查询失败，"+msg1);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg1.length()>50){
                            updateparam.put("errMsg","接口：saveZzsfxx上传失败"+msg1.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：saveZzsfxx上传失败"+msg1);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONArray data1arr = qeuryRXGIDByIdNoResultObj.getJSONArray("DATA");
                    if(data1arr==null || (data1arr!=null && data1arr.size()==0))
                    {
                        logger.info("****接口：QeuryRXGIDByIdNo 返回结果中DATA为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryRXGIDByIdNo 返回结果中DATA为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
//{"SUCCESS":"1","MESSAGE":"","DATA":[{"PE_ID":"6407a78c-0c09-4fa9-926f-5aa2f04fa946","PERSON_INDEX":"073826501","ID_NO":"452128198307116045","YEAR_REPORTED":"2022","QUARTERLY_REPORTED":"3","BH":""}]}
//                    JSONObject data1Index0 = (JSONObject) data1arr.get(0);
//                    String pId = String.valueOf(data1Index0.get("PE_ID") == null ? "" : data1Index0.get("PE_ID"));
//                    String personIndex = String.valueOf(data1Index0.get("PERSON_INDEX") == null ? "" : data1Index0.get("PERSON_INDEX"));
                    String pId="";
                    String personIndex="";
                    //返回的数据有多条，要找到对应体检号这条
                    for (int i = 0; i < data1arr.size(); i++) {
                        JSONObject jsonObject = data1arr.getJSONObject(i);
                        String PE_ID = jsonObject.getString("PE_ID");
                        if (PE_ID.equals(peId+visitid)) {
                            pId = String.valueOf(jsonObject.get("PE_ID") == null ? "" : jsonObject.get("PE_ID"));
                            personIndex = String.valueOf(jsonObject.get("PERSON_INDEX") == null ? "" : jsonObject.get("PERSON_INDEX"));
                        }
                    }
                    logger.info("****接口：QeuryRXGIDByIdNo 返回结果中PId："+pId +",personIndex:"+personIndex);
                    if("".equals(pId))
                    {
                        logger.info("****接口：QeuryRXGIDByIdNo 返回结果中DATA中：PE_ID为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId",peId);
                        updateparam.put("visitid",visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryRXGIDByIdNo 返回结果中DATA中：PE_ID为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    if("".equals(personIndex))
                    {
                        logger.info("****接口：QeuryRXGIDByIdNo 返回结果中DATA中：person_index为空");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId", peId);
                        updateparam.put("visitid", visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：QeuryRXGIDByIdNo 返回结果中DATA中：person_index为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    //上报
                    HashMap params2 = new HashMap();

                    params2.put("peId",peId);
                    params2.put("visitid",visitid);

                    //上传的体检号=体检号+体检次数
                    String getPeId = peId + visitid;
                    params2.put("getPeId",getPeId);

                    params2.put("personIndex",personIndex);
                    params2.put("pId",pId);

                    //测试数据
                    // params2.put("personIndex","9999");
                    // params2.put("pId","TJ01937443");

                    String followUp = String.valueOf(info.get("FOLLOW_UP") == null ? "" : info.get("FOLLOW_UP"));
                    params2.put("followUp",followUp);

                    String pathologicalExamination = String.valueOf(info.get("PATHOLOGICAL_EXAM_INATION") == null ? "" : info.get("PATHOLOGICAL_EXAM_INATION"));
                    params2.put("pathologicalExamination",pathologicalExamination);

                    String checkUnitcode1 = String.valueOf(info.get("CHECK_UNITCODE1") == null ? "4501030014" : info.get("CHECK_UNITCODE1"));
                    params2.put("checkUnitcode1",checkUnitcode1);

                    String checkUnitname1 = String.valueOf(info.get("CHECK_UNITNAME1") == null ? "广西壮族自治区人民医院" : info.get("CHECK_UNITNAME1"));
                    params2.put("checkUnitname1",checkUnitname1);

                    String inoutSign1 = String.valueOf(info.get("INOUT_SIGN1") == null ? "0" : info.get("INOUT_SIGN1"));
                    params2.put("inoutSign1",inoutSign1);

                    String pathologicalDiagnosis = String.valueOf(info.get("PARHOLOGICAL_DIAGNOSIS") == null ? "" : info.get("PARHOLOGICAL_DIAGNOSIS"));
                    params2.put("pathologicalDiagnosis",pathologicalDiagnosis);


                    String pathologicalExaminationDatestr = String.valueOf(info.get("PARHOLOGICAL_EXAMINATION_DATE") == null ? "" : info.get("PARHOLOGICAL_EXAMINATION_DATE"));
                    String pathologicalExaminationDate ="";
                    if(!("".equals(pathologicalExaminationDatestr)))
                    {
                        pathologicalExaminationDate = pathologicalExaminationDatestr.substring(0,10);
                    }
                    params2.put("pathologicalExaminationDate",pathologicalExaminationDate);

                    String pathologicalFindings = String.valueOf(info.get("PARHOLOGICAL_FINDINGS") == null ? "" : info.get("PARHOLOGICAL_FINDINGS"));
                    params2.put("pathologicalFindings",pathologicalFindings);

                    String benignDiseases = String.valueOf(info.get("BEGIN_DISEASES") == null ? "" : info.get("BEGIN_DISEASES"));
                    params2.put("benignDiseases",benignDiseases);

                    String clinicalStages = String.valueOf(info.get("CLINICAL_STAGES") == null ? "" : info.get("CLINICAL_STAGES"));
                    params2.put("clinicalStages",clinicalStages);

                    String whetherStaging = String.valueOf(info.get("WHETHER_STAGING") == null ? "" : info.get("WHETHER_STAGING"));
                    params2.put("whetherStaging",whetherStaging);

                    String t = String.valueOf(info.get("T") == null ? "" : info.get("T"));
                    params2.put("t",t);

                    String n = String.valueOf(info.get("N") == null ? "" : info.get("N"));
                    params2.put("n",n);

                    String m = String.valueOf(info.get("M") == null ? "" : info.get("M"));
                    params2.put("m",m);

                    String ctnm = String.valueOf(info.get("CTNM") == null ? "" : info.get("CTNM"));
                    params2.put("ctnm",ctnm);

                    String pathologicalStaging = String.valueOf(info.get("PATHOLOGICAL_STAGING") == null ? "" : info.get("PATHOLOGICAL_STAGING"));
                    params2.put("pathologicalStaging",pathologicalStaging);

                    String whether_staging2 = String.valueOf(info.get("WHETHER_STAGING2") == null ? "" : info.get("WHETHER_STAGING2"));
                    params2.put("whether_staging2",whether_staging2);

                    String t2 = String.valueOf(info.get("T2") == null ? "" : info.get("T2"));
                    params2.put("t2",t2);

                    String n2 = String.valueOf(info.get("N2") == null ? "" : info.get("N2"));
                    params2.put("n2",n2);

                    String m2 = String.valueOf(info.get("M2") == null ? "" : info.get("M2"));
                    params2.put("m2",m2);

                    String ptnm = String.valueOf(info.get("PTNM") == null ? "" : info.get("PTNM"));
                    params2.put("ptnm",ptnm);


                    String checkUnitcode2 = String.valueOf(info.get("CHECK_UNITCODE2") == null ? "4501030014" : info.get("CHECK_UNITCODE2"));
                    params2.put("checkUnitcode2",checkUnitcode2);

                    String checkUnitname2 = String.valueOf(info.get("CHECK_UNITNAME2") == null ? "广西壮族自治区人民医院" : info.get("CHECK_UNITNAME2"));
                    params2.put("checkUnitname2",checkUnitname2);

                    String inoutSign2 = String.valueOf(info.get("INOUT_SIGN2") == null ? "0" : info.get("INOUT_SIGN2"));
                    params2.put("inoutSign2",inoutSign2);

                    String treatmentStatus = String.valueOf(info.get("TREATMENT_STATUS") == null ? "" : info.get("TREATMENT_STATUS"));
                    params2.put("treatmentStatus",treatmentStatus);


                    String diagnosisDatestr = String.valueOf(info.get("DIAGNOSIS_DATE") == null ? "" : info.get("DIAGNOSIS_DATE"));
                    String diagnosisDate ="";
                    if(!("".equals(diagnosisDatestr)))
                    {
                        diagnosisDate = diagnosisDatestr.substring(0,10);
                    }
                    params2.put("diagnosisDate",diagnosisDate);

                    String tpl2 = ReadTpltoStr.readTol("tpl_SaveZzsfxx.xml");
                    String tpl2ReqXml = fillParamsToTpl(tpl2,params2 );
                    logger.info("****入参:"+ tpl2ReqXml );
                    String result2 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl2ReqXml,_INFURL);
                    logger.info("****出参:"+result2);

                    if(result2==null ||"".equals(result2))
                    {
                        // errList.add(info);
                        logger.info("****接口：SaveZzsfxx，返回为空！");
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId", peId);
                        updateparam.put("visitid", visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        updateparam.put("errMsg","接口：SaveZzsfxx上传失败，返回为空");
                        updateUploadStatus(updateparam);
                        continue;
                    }
                    JSONObject json2 =  Xml2Json.xmltoJson(result2);
                    logger.info("****json2"+json2);
                    JSONObject envelopeObj2 = (JSONObject) json2.get("Envelope");
                    JSONObject bodyObj2 = (JSONObject) envelopeObj2.get("Body");
                    JSONObject saveZzsfxxResponseObj2 = (JSONObject) bodyObj2.get("SaveZzsfxxResponse");
                    JSONObject saveZzsfxxResult2 =JSONObject.parseObject (String.valueOf( saveZzsfxxResponseObj2.get("SaveZzsfxxResult")));

                    String resultCode2 = saveZzsfxxResult2.getString("SUCCESS");
                    String msg2 = saveZzsfxxResult2.getString("MESSAGE");
                    if(!"1".equals(resultCode2))
                    {
                        logger.info("****接口：SaveZzsfxx上传失败，"+msg2);
                        //更新 上传状态
                        HashMap updateparam  = new HashMap();
                        updateparam.put("peId", peId);
                        updateparam.put("visitid", visitid);
                        updateparam.put("idNo",idNo);
                        updateparam.put("sendOrderId",sendOrderId);
                        updateparam.put("tableName",tableName);
                        updateparam.put("uploadStatus","0");
                        if(msg2.length()>50){
                            updateparam.put("errMsg","接口：SaveZzsfxx上传失败"+msg2.substring(0,50));
                        }
                        else
                        {
                            updateparam.put("errMsg","接口：SaveZzsfxx上传失败"+msg2);
                        }

                        updateUploadStatus(updateparam);
                        continue;
                    }

                    //更新 上传状态
                    HashMap updateparam  = new HashMap();
                    updateparam.put("peId", peId);
                    updateparam.put("visitid", visitid);
                    updateparam.put("idNo",idNo);
                    updateparam.put("sendOrderId",sendOrderId);
                    updateparam.put("tableName",tableName);
                    updateparam.put("uploadStatus","1");
                    updateparam.put("errMsg","succ");
                    updateUploadStatus(updateparam);

                }
            }catch (Exception e){
                //errList.add(info);
                e.printStackTrace();
            }
        }
        return resultMsg;
    }


    /**
     *保存宫颈癌妇科检查
     * @param sendOrderId
     * @param tableName GJGFKJC
     * @param idNo 身份证
     * @return
     */
    @RequestMapping("/saveGjgFkjc")
    @ResponseBody
    public void saveGjgFkjc(String sendOrderId,String tableName,String peId,String visitid,String idNo)
    {
        try {
            boolean continueflag = true;

            HashMap params1 = new HashMap();
            params1.put("IdNo", idNo);
            String tpl1 = ReadTpltoStr.readTol("tpl_QeuryGJAIDByIdNo.xml");
            String tpl1ReqXml = fillParamsToTpl(tpl1, params1);
            logger.info("****入参:" + tpl1ReqXml);
            String result1 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl1ReqXml, _INFURL);
            logger.info("****出参:" + result1);

            if (result1 == null || "".equals(result1)) {
                //errList.add(info);
                logger.info("****接口：QeuryGJAIDByIdNo查询失败，返回为空！");
                //更新 上传状态
                HashMap updateparam = new HashMap();
                updateparam.put("peId", peId);
                updateparam.put("visitid", visitid);
                updateparam.put("tableName", "GJGFKJC");
                updateparam.put("sendOrderId", sendOrderId);
                updateparam.put("uploadStatus", "0");
                updateparam.put("errMsg", "接口：QeuryGJAIDByIdNo查询失败，返回为空");
                updateUploadStatus2(updateparam);
                continueflag = false;
            }

            if (continueflag) {
                JSONObject json1 = Xml2Json.xmltoJson(result1);
                //{"Envelope":{"Body":{"QeuryGJAIDByIdNoResponse":{"QeuryGJAIDByIdNoResult":"{\"SUCCESS\":\"1\",\"MESSAGE\":\"\",\"DATA\":[]}"}}}}
                JSONObject envelopeObj = (JSONObject) json1.get("Envelope");
                JSONObject bodyObj = (JSONObject) envelopeObj.get("Body");
                JSONObject qeuryGJAIDByIdNoResponseObj = (JSONObject) bodyObj.get("QeuryGJAIDByIdNoResponse");
                JSONObject qeuryGJAIDByIdNoResultObj = JSONObject.parseObject(String.valueOf(qeuryGJAIDByIdNoResponseObj.get("QeuryGJAIDByIdNoResult")));

                String resultCode1 = qeuryGJAIDByIdNoResultObj.getString("SUCCESS");
                String msg1 = qeuryGJAIDByIdNoResultObj.getString("MESSAGE");
                if (!"1".equals(resultCode1))
                {
                    logger.info("****接口：QeuryGJAIDByIdNo查询失败，" + msg1);
                    //更新 上传状态
                    HashMap updateparam = new HashMap();
                    updateparam.put("peId", peId);
                    updateparam.put("visitid", visitid);
                    updateparam.put("tableName", "GJGFKJC");
                    updateparam.put("sendOrderId", sendOrderId);
                    updateparam.put("uploadStatus", "0");
                    if (msg1.length() > 50) {
                        updateparam.put("errMsg", "接口：SaveGjgHpv上传失败" + msg1.substring(0, 50));
                    } else {
                        updateparam.put("errMsg", "接口：SaveGjgHpv上传失败" + msg1);
                    }

                    updateUploadStatus2(updateparam);

                } else
                    {
                    JSONArray data1arr = qeuryGJAIDByIdNoResultObj.getJSONArray("DATA");
                    if (data1arr == null || (data1arr != null && data1arr.size() == 0)) {
                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA为空");
                        //更新 上传状态
                        HashMap updateparam = new HashMap();
                        updateparam.put("peId", peId);
                        updateparam.put("visitid", visitid);
                        updateparam.put("tableName", "GJGFKJC");
                        updateparam.put("sendOrderId", sendOrderId);
                        updateparam.put("uploadStatus", "0");
                        updateparam.put("errMsg", "接口：QeuryGJAIDByIdNo 返回结果中DATA为空");
                        updateUploadStatus2(updateparam);

                    } else  {
                        //{"SUCCESS":"1","MESSAGE":"","DATA":[{"PE_ID":"6407a78c-0c09-4fa9-926f-5aa2f04fa946","PERSON_INDEX":"073826501","ID_NO":"452128198307116045","YEAR_REPORTED":"2022","QUARTERLY_REPORTED":"3","BH":""}]}
//                        JSONObject data1Index0 = (JSONObject) data1arr.get(0);
                        String pId="";
                        String personIndex="";
                        //返回的数据有多条，要找到对应体检号这条
                        for (int i = 0; i < data1arr.size(); i++) {
                            JSONObject jsonObject = data1arr.getJSONObject(i);
                            String PE_ID = jsonObject.getString("PE_ID");
                            if (PE_ID.equals(peId+visitid)) {
                                pId = String.valueOf(jsonObject.get("PE_ID") == null ? "" : jsonObject.get("PE_ID"));
                                personIndex = String.valueOf(jsonObject.get("PERSON_INDEX") == null ? "" : jsonObject.get("PERSON_INDEX"));
                            }
                        }


                        logger.info("****接口：QeuryGJAIDByIdNo 返回结果中PId：" + pId + ",personIndex:" + personIndex);
                        if ("".equals(pId)) {
                            logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA中：PE_ID为空");
                            //更新 上传状态
                            HashMap updateparam = new HashMap();
                            updateparam.put("peId", peId);
                            updateparam.put("visitid", visitid);
                            updateparam.put("tableName", "GJGFKJC");
                            updateparam.put("sendOrderId", sendOrderId);
                            updateparam.put("uploadStatus", "0");
                            updateparam.put("errMsg", "接口：QeuryGJAIDByIdNo 返回结果中DATA中：PE_ID为空");
                            updateUploadStatus2(updateparam);

                        } else {
                            if ("".equals(personIndex)) {
                                logger.info("****接口：QeuryGJAIDByIdNo 返回结果中DATA中：person_index为空");
                                //更新 上传状态
                                HashMap updateparam = new HashMap();
                                updateparam.put("peId", peId);
                                updateparam.put("visitid", visitid);
                                updateparam.put("tableName", "GJGFKJC");
                                updateparam.put("sendOrderId", sendOrderId);
                                updateparam.put("uploadStatus", "0");
                                updateparam.put("errMsg", "接口：QeuryGJAIDByIdNo 返回结果中DATA中：person_index为空");
                                updateUploadStatus2(updateparam);

                            } else {

                                HashMap qryparam = new HashMap();
                                qryparam.put("peId", peId);
                                qryparam.put("visitid", visitid);
                                qryparam.put("tableName", "GJGFKJC");
                                qryparam.put("sendOrderId", sendOrderId);

                                List<HashMap> uploadList = healthPatInfoService.queryUploadGjgFkjc(qryparam);
                                if (uploadList != null && uploadList.size() > 0) {
                                    // List<HashMap> errList = new ArrayList<HashMap>();
                                    for (HashMap info : uploadList) {
                                        HashMap params2 = new HashMap();
                                        params2.put("peId", peId);
                                        params2.put("personIndex", personIndex);
                                        params2.put("pId", pId);

                                        //上传的体检号=体检号+体检次数
                                        String getPeId = peId + visitid;
                                        params2.put("getPeId",getPeId);

                                        String examination = String.valueOf(info.get("EXAMINATION") == null ? "" : info.get("EXAMINATION"));
                                        params2.put("examination", examination);

                                        String condylomaAcuminatum = String.valueOf(info.get("CONDYLOMA_ACUMINATUM") == null ? "" : info.get("CONDYLOMA_ACUMINATUM"));
                                        params2.put("condylomaAcuminatum", condylomaAcuminatum);

                                        String trichomonasVaginitis = String.valueOf(info.get("TRICHOMONAS_VAGINITIS") == null ? "" : info.get("TRICHOMONAS_VAGINITIS"));
                                        params2.put("trichomonasVaginitis", trichomonasVaginitis);

                                        String vulvovaginalCandidiasis = String.valueOf(info.get("VULVOVAGINAL_CANDIDIASIS") == null ? "" : info.get("VULVOVAGINAL_CANDIDIASIS"));
                                        params2.put("vulvovaginalCandidiasis", vulvovaginalCandidiasis);

                                        String bacterialVaginosis = String.valueOf(info.get("BACTERIAL_VAGINOSIS") == null ? "" : info.get("BACTERIAL_VAGINOSIS"));
                                        params2.put("bacterialVaginosis", bacterialVaginosis);

                                        String mucopurulentCervicitis = String.valueOf(info.get("MUCOPURULENT_CERVICITIS") == null ? "" : info.get("MUCOPURULENT_CERVICITIS"));
                                        params2.put("mucopurulentCervicitis", mucopurulentCervicitis);

                                        String cervicalPolyp = String.valueOf(info.get("CERVICAL_POLYP") == null ? "" : info.get("CERVICAL_POLYP"));
                                        params2.put("cervicalPolyp", cervicalPolyp);

                                        String fibroid = String.valueOf(info.get("FIBROID") == null ? "" : info.get("FIBROID"));
                                        params2.put("fibroid", fibroid);

                                        String other = String.valueOf(info.get("OTHER") == null ? "" : info.get("OTHER"));
                                        params2.put("other", other);

                                        String checkUnitcode1 = String.valueOf(info.get("CHECK_UNITCODE1") == null ? "4501030014" : info.get("CHECK_UNITCODE1"));
                                        params2.put("checkUnitcode1", checkUnitcode1);

                                        String checkUnitname1 = String.valueOf(info.get("CHECK_UNITNAME1") == null ? "广西壮族自治区人民医院" : info.get("CHECK_UNITNAME1"));
                                        params2.put("checkUnitname1", checkUnitname1);

                                        String inoutSign1 = String.valueOf(info.get("INOUT_SIGN1") == null ? "0" : info.get("INOUT_SIGN1"));
                                        params2.put("inoutSign1", inoutSign1);

                                        String checkPerson = String.valueOf(info.get("CHECK_PERSON") == null ? "" : info.get("CHECK_PERSON"));
                                        params2.put("checkPerson", checkPerson);

                                        String checkDatestr = String.valueOf(info.get("CHECK_DATE") == null ? "" : info.get("CHECK_DATE"));
                                        String checkDate = "";
                                        if (!("".equals(checkDatestr))) {
                                            checkDate = checkDatestr.substring(0, 10);
                                        }
                                        params2.put("checkDate", checkDate);


                                        String tpl2 = ReadTpltoStr.readTol("tpl_SaveGjgFkjc.xml");
                                        String tpl2ReqXml = fillParamsToTpl(tpl2, params2);
                                        logger.info("****入参:" + tpl2ReqXml);
                                        String result2 = HttpUrlConnectionToInterface.httpsUrlConnectionPost(tpl2ReqXml, _INFURL);
                                        logger.info("****出参:" + result2);

                                        if (result2 == null || "".equals(result2)) {
                                            // errList.add(info);
                                            logger.info("****接口：SaveGjgFkjc上传失败，返回为空！");
                                            //更新 上传状态
                                            HashMap updateparam = new HashMap();
                                            updateparam.put("peId", peId);
                                            updateparam.put("visitid", visitid);
                                            updateparam.put("tableName", "GJGFKJC");
                                            updateparam.put("sendOrderId", sendOrderId);
                                            updateparam.put("uploadStatus", "0");
                                            updateparam.put("errMsg", "接口：SaveGjgFkjc上传失败，返回为空");
                                            updateUploadStatus2(updateparam);
                                            continue;
                                        }
                                        JSONObject json2 = Xml2Json.xmltoJson(result2);
                                        logger.info("****json2" + json2);

                                        JSONObject envelopeObj2 = (JSONObject) json2.get("Envelope");
                                        JSONObject bodyObj2 = (JSONObject) envelopeObj2.get("Body");
                                        JSONObject saveGjgFkjcResponseObj2 = (JSONObject) bodyObj2.get("SaveGjgFkjcResponse");
                                        JSONObject saveGjgFkjcResult2 = JSONObject.parseObject(String.valueOf(saveGjgFkjcResponseObj2.get("SaveGjgFkjcResult")));

                                        String resultCode2 = saveGjgFkjcResult2.getString("SUCCESS");
                                        String msg2 = saveGjgFkjcResult2.getString("MESSAGE");
                                        if (!"1".equals(resultCode2)) {
                                            logger.info("****接口：SaveGjgFkjc上传失败，" + msg2);
                                            //更新 上传状态
                                            HashMap updateparam = new HashMap();
                                            updateparam.put("peId", peId);
                                            updateparam.put("visitid", visitid);
                                            updateparam.put("tableName", "GJGFKJC");
                                            updateparam.put("sendOrderId", sendOrderId);
                                            updateparam.put("uploadStatus", "0");
                                            if (msg2.length() > 50) {
                                                updateparam.put("errMsg", "接口：SaveGjgFkjc上传失败" + msg2.substring(0, 50));
                                            } else {
                                                updateparam.put("errMsg", "接口：SaveGjgFkjc上传失败" + msg2);
                                            }

                                            updateUploadStatus2(updateparam);
                                            continue;
                                        }

                                        //更新 上传状态
                                        HashMap updateparam = new HashMap();
                                        updateparam.put("peId", peId);
                                        updateparam.put("visitid", visitid);
                                        updateparam.put("tableName", "GJGFKJC");
                                        updateparam.put("sendOrderId", sendOrderId);
                                        updateparam.put("uploadStatus", "1");
                                        updateparam.put("errMsg", "succ");
                                        updateUploadStatus2(updateparam);
                                    }
                                }
                            }
                        }

                    }

                }

            }
        }catch(Exception e){
            e.printStackTrace();
        }

    }

    public void updateUploadStatus2(HashMap updateparam)
    {
        try {
            healthPatInfoService.updateUploadStatus2(updateparam);
        }catch (Exception  e){
            e.printStackTrace();
        }
    }
}
